0

My issue is already discussed here couldn't open file "" error in Facebook PHP API

and my php script is

//variables we are going to post to facebook
$fbPermissions = 'publish_stream,user_photos';  //Required facebook permissions
$PicLocation = 'fb_cover_images/cover7.jpg';
$msg_body = array(
    'message' => 'I liked this pic from '. $homeurl .
     ' it is perfect for my cover photo.',
     'url' => "http://my_site.com/$PicLocation"
);

if ($fbuser){ //user is logged in to facebook, post our image
  try {
     $uploadPhoto = $facebook->api('/me/photos', 'post', $msg_body );
  } 
  catch (FacebookApiException $e) {
    echo $e->getMessage(); //output any error
  }
}
else{
  $loginUrl = $facebook->getLoginUrl(
  array('scope'=>$fbPermissions,'return_url'=>$return_url));
  header('Location: ' . $loginUrl);
}

If I set 'url' => "http://my_site.com/$PicLocation" then getting

(#200) Permissions error

and If I set 'url' => "@http://my_site.com/$PicLocation" then getting

couldn't open file "http://my_site.com/fb_cover_images/cover7.jpg"

message though if I hit "http://my_site.com/fb_cover_images/cover7.jpg", I can view image and permission to folder+image is set to 777.

Please guide what I am doing wrong.... I have searched but fail.

I also tried [PHP + Facebook: how to upload photo on the wall? but same rubbish message (#200) Permissions error

Also Upload Photo To Album with Facebook's Graph API I don't know what the hell is going on with FB API.

Community
  • 1
  • 1
user1777018
  • 69
  • 2
  • 9
  • just some tips: "publish_actions" is the only permission you need. and you don´t need 777 permissions on the folder. after all you don´t want to write something, but just read the image and put it on facebook. and another thing: the message parameter needs to be 100% user generated. just saying. – andyrandy May 17 '14 at 09:19
  • updated `$fbPermissions = 'publish_stream,user_photos,publish_actions'; //Required facebook permissions` but same issues :( – user1777018 May 17 '14 at 09:40
  • again, publish_actions is the ONLY permission you need. you really need to check out the facebook docs about permissions. don´t use permissions "just because they work", remove all unneccessary ones. – andyrandy May 17 '14 at 10:29
  • and of course this may not solve the problem at hand, but it is a very important thing to notice. – andyrandy May 17 '14 at 10:30
  • I also tried [PHP + Facebook: how to upload photo on the wall?](http://stackoverflow.com/questions/13407800/php-facebook-how-to-upload-photo-on-the-wall) but same rubbish message `(#200) Permissions error` – user1777018 May 17 '14 at 11:57
  • please somebody guide me.... I have already spend two days on this issue. – user1777018 May 17 '14 at 11:58
  • can somebody explain me what should be the format for `$FILE_PATH` and what actually `$args['image']` have? – user1777018 May 17 '14 at 12:02
  • I dont know what the hell is going on with the FB API..... :( – user1777018 May 17 '14 at 12:19
  • are you sure the picture is available and not behind a login or so? i just checked in one of my projects, i am using the direct url like this and it works: "https://myserver.com/myimage.jpg" – andyrandy May 17 '14 at 14:05

1 Answers1

0

Try adding the following line to the top of your code, after setting up Facebook:

$facebook->setFileUploadSupport( true );

Then, change your $msg_body to the following:

$msg_body = array(
  'name' => 'I liked this pic from '. $homeurl . ' it is perfect for my cover photo.',
  'source' => "http://my_site.com/$PicLocation"
);

The name is the caption for the image, and the source is the URL to the file. You only need to prefix @ to the source if you are referencing a local file.

Niraj Shah
  • 15,087
  • 3
  • 41
  • 60