Arthur Ferreira
Arthur Ferreira

Reputation: 321

Can't share pictures using Facebook API

I'm quite new to the Facebook API, and at the moment I'm using the Facebook PHP SDK. So, I was interested on sharing a certain picture automatically from facebook (like http://www.facebook.com/photo.php?fbid=10150286544861729&set=a.10150286544851729.375565.20531316728&type=1) on my wall (/me/links/). So, at the POST request, I send the parameters "source" and "link", referring both to the same URL (the image URL). But I get the OAuthException "(#1500) The url you supplied is invalid".

I've permitted both "publish_stream" and "share_item" permissions, but the most awkward thing is that it seems there isn't any problem with my code, but with the app settings somehow, since I get the same error if I use the Graph API Explorer, generating an access token with the same permissions.

What am I missing here?

Nevermind, now the graph API explorer is working fine, I just generated another token and it worked fine. So, the problem may be with the code, so here it goes:

    $share = $facebook->api('/me/links', 'POST', array(
                            'source' => urlencode($temp_test),
                            'link' => urlencode($temp_test),
                            ));

Is there anything wrong with it?

Upvotes: 0

Views: 3100

Answers (2)

mahboudz
mahboudz

Reputation: 39376

If you already have an image in your album on Facebook and want to share the image on your timeline or a friend's, then you can use the object_attachment tag. This is how you do it in Obj-C:

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   //                                 @"http://www.bitsonthego.com", @"link",
                                   {image id of your image goes here}, @"object_attachment",
                                   @"my profile", @"name",
                                   @"description", @"description",
                                   @"name of the post", @"name",
                                   @"caption of my post", @"caption",
                                   @"a message", @"message",
                                   nil];

    [facebook requestWithGraphPath:@"/me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self]; 

No need to make another copy of your image or host it locally.

Upvotes: 1

Inam Abbas
Inam Abbas

Reputation: 1480

You can not share image which are hosted on facebook. What you can do it copy that image first on your server using PHP copy() function and pass then pass the URL of image from your server.

i.e copy("http://www.facebook.com/photo.php?fbid=10150286544861729&set=a.10150286544851729.375565.20531316728&type=1", "/folder location on your server/image.jpg");

$share = $facebook->api('/me/links', 'POST', array(
                            'source' => "http://yourserver.com".$folder_path.$image,
                            'link' => urlencode($temp_test),
                            ));

Upvotes: 1

Related Questions