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

发布于 2024-10-21 13:12:50 字数 579 浏览 3 评论 0原文

我有一个关于 Facebook API 的问题。我创建了一个应用程序“屏幕截图提交”,从提交屏幕截图的概念来看,场景是:

  1. 用户允许我的应用程序后。
  2. 用户将使用表单选择要在应用程序上上传的文件,然后提交。
  3. 我想将所选文件(图像/照片)上传到他/她的相册(从应用程序自动生成)并将文件(图像/照片)发布到他/她的墙上。

    $photo_details = array('message'=>$_REQUEST['arttitle'],'source'=> '@' .realpath($_FILES[file]tmp_name]));
    
    $facebook->api('/me/photos','POST',$photo_details);
    

上面的代码将上传照片到自动生成的相册,并返回一个数组,如下所示:

Array([id]=1234567890)

现在,如何使用 php.sdk 和 graph 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. 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟花肆意 2024-10-28 13:12:50

首先获取publish_stream的扩展权限。然后以下代码将帮助将照片上传到墙上

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

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);
望喜 2024-10-28 13:12:50

上传照片后,您将返回“照片的object_id”。

使用“object_attachment = '照片的object_id'”在 facebook 墙上发布帖子

curl -F \ "access_token=..." \
-F“消息=等等等等……”
-F "object_attachment=照片的object_id" \
“https://graph.facebook.com/me/feed

更多信息请参见 http://developers.facebook.com/docs/reference/api/user/ posts 部分

object_attachment:用户相册中用作缩略图的现有图片的 Facebook ID。照片的所有者,并且照片不能是邮件附件的一部分。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文