FB upload photo from application and post it to user's wall
I have a problem regarding the Facebook API. I've created an application "Screenshot Submission", from the concept of s开发者_开发问答ubmitting the screenshot, the scenario is:
- After the users allows my application.
- The user will select a file to upload on the application using form then submit it.
I want to upload the selected file(image/photo) to his/her album(auto generated from application) and post the file(image/photo) to his/her wall.
$photo_details = array('message'=>$_REQUEST['arttitle'],'source'=> '@' . realpath($_FILES[file]tmp_name])); $facebook->api('/me/photos','POST',$photo_details);
The above code will upload photo to the autogenerated album, and returns an array like:
Array([id]=1234567890)
Now, how can post the uploaded file(image/photo) to his/her wall using php.sdk and graph api.
Any help would be appreciated. Thanks.
First take the extended permission of publish_stream. Then the following code will help to upload the photo to wall
$attachment = array(
'message' => 'The message that you want to display with picture',
'name' =>'Your Application Name',
'caption' => "Caption Under the picture",
'link' => 'http://apps.facebook.com/yourapplication/',
'description' => 'Some description with picture about picture or your application',
'picture' => 'http://www.yoursite.com/somefolder/images/'.$Picturetoupload,
'method'=>'stream.publish',
'actions' => array(
array(
'name' => 'Your Application Name',
'link' => 'http://apps.facebook.com/Yourapplicationlink/'
)
)
);
$uid=$fbme['id']; // id of the user
$result = $facebook->api('/'.$uid.'/feed/','post',$attachment);
After uploading the photo, you will get the "object_id of the photo" in return.
Make a post to facebook wall with "object_attachment = 'object_id of the photo'"
curl -F \ "access_token=..." \
-F "message=blah blah...."
-F "object_attachment=object_id of the photo" \
"https://graph.facebook.com/me/feed
more info in http://developers.facebook.com/docs/reference/api/user/ posts section.
object_attachment:Facebook ID for an existing picture in the User's photo albums to use as the thumbnail image. The User must be the owner of the photo, and the photo cannot be part of a message attachment.
精彩评论