无法使用Facebook API分享图片

时间:2012-02-04 23:21:43

标签: facebook api permissions

我对Facebook API很新,目前我正在使用Facebook PHP SDK。所以,我有兴趣在我的墙上自动分享某张图片(如http://www.facebook.com/photo.php?fbid=10150286544861729&set=a.10150286544851729.375565.20531316728&type=1)(/ me / links /)。 因此,在POST请求中,我发送参数“source”和“link”,同时引用相同的URL(图像URL)。但是我得到OAuthException“(#1500)你提供的网址无效”。

我已经允许“publish_stream”和“share_item”权限,但最尴尬的是,我的代码似乎没有任何问题,但是以某种方式应用程序设置,因为我得到相同的错误,如果我使用Graph API Explorer,生成具有相同权限的访问令牌。

我在这里缺少什么?

没关系,现在图形API资源管理器工作正常,我只是生成了另一个令牌,它工作正常。所以,问题可能在于代码,所以在这里:

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

它有什么问题吗?

2 个答案:

答案 0 :(得分:1)

您无法共享在Facebook上托管的图片。您可以使用PHP copy()函数首先在服务器上复制该图像,然后传递然后从服务器传递图像的URL。

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),
                            ));

答案 1 :(得分:1)

如果您在Facebook上的相册中已有图像并希望在时间轴或朋友上共享图像,则可以使用object_attachment标记。这就是你在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]; 

无需制作图像的其他副本或在本地托管。