I'm trying to post a photo to one of friends wall using the new graph api. For this I have the following code:
$attachment = array(
'message' => 'Posted a photo',
'source' => '@' . realpath(PATH_TO_MY_PHOTO)
);
$facebook->setFileUploadSupport(true);
$facebook->api('/'.$id_friend.'/feed?access_token='.$access_token, 'post', $attachment);
The problem is that the picture is not uploaded. I mean, it only post the message without any picture. This does not work either if I try to post on the current user wall.开发者_如何学JAVA
Does anyone have any idea on how to achieve this ? Thanks.
p.s. I'm requesting only publish_stream permission
In order to post a poto to a users wall, as in publishing a photo and not a stream story, you can post to here:
http://graph.facebook.com/ALBUM_ID/photos.
for more information visit facebook's graph api photo documentation.
You should replace "source" with "picture".
$imagepath='http://site.com/pic.jpg';
$attachment = array( 'message' => 'Posted a photo', 'picture' => $imagepath );
$facebook->setFileUploadSupport(true); $facebook->api('/'.$id_friend.'/feed?access_token='.$access_token, 'post', $attachment)
You can optionally add some more fields. for more details: https://developers.facebook.com/docs/reference/api/post/
精彩评论