FB upload photo from application and post it to user's wall

瘦欲@ 提交于 2020-01-03 01:22:35

问题


I have a problem regarding the Facebook API. I've created an application "Screenshot Submission", from the concept of submitting the screenshot, the scenario is:

  1. After the users allows my application.
  2. The user will select a file to upload on the application using form then submit it.
  3. 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.


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/5297608/fb-upload-photo-from-application-and-post-it-to-users-wall

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!