FB从应用程序上传照片并将其发布到用户的墙上

FB从应用程序上传照片并将其发布到用户的墙上

问题描述:

我对Facebook API有疑问.我已经创建了一个应用程序截屏提交",从提交截屏的概念来看,场景是:

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. 在用户允许我的应用程序之后.
  2. 用户将使用表格选择要上传到应用程序的文件,然后提交.
  3. 我想将所选文件(图像/照片)上传到他/她的相册(通过应用程序自动生成),然后将文件(图像/照片)发布到他/她的墙上.

  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)

现在,如何使用php.sdk和graph api将上传的文件(图像/照片)发布到他/她的墙上.

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.

首先获得 publish_stream .然后,以下代码将有助于将照片上传到墙上

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