php curl upload linkedin image

Solutions on MaxInterview for php curl upload linkedin image by the best coders in the world

showing results for - "php curl upload linkedin image"
Ignacio
21 Aug 2019
1// Working example of uploading image to share on linkedin 
2//https://docs.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/share-on-linkedin?context=linkedin/marketing/context#creating-a-share-on-linkedin
3$uploadUrl = $r->value->uploadMechanism->{"com.linkedin.digitalmedia.uploading.MediaUploadHttpRequest"}->uploadUrl;
4$file_name_with_full_path="/full/path/tofile.png";
5$access_token="your_user_access_token_here";
6
7$mimeType= mime_content_type($file_name_with_full_path);
8$headers = array(
9    'Authorization: Bearer '.$access_token,
10    "X-RestLi-Protocol-Version:2.0.0",
11    "Content-Type: {$mimeType}"
12);
13$ch = curl_init($uploadUrl);
14curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
15curl_setopt($ch, CURLOPT_TIMEOUT, 30);
16curl_setopt($ch,CURLOPT_USERAGENT,'curl/7.35.0');
17curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
18curl_setopt($ch, CURLOPT_POST, true);
19curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
20curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
21curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
22curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($file_name_with_full_path));
23$response = curl_exec($ch);