使用网络服务器上的照片离线将照片上传到 Facebook
我到处搜索,但没有运气,找到了很多在用户处于会话中时将照片上传到 Facebook 的示例(即用户实际坐在计算机前并访问网页)。我已经尝试过这些示例,并且它们有效。
我注意到去年关于同一问题的这个未回答的问题 Stackoverflow 问题
我当前的 问题应用程序允许用户授权离线更新,我存储 access_token、user_id 等,并且当用户离线时我可以成功发布到用户墙。
我真的很难找到将照片发布到用户墙上的方法。阅读 Facebook 文档,我认为您只能使用以下方式上传照片多部分/表单数据!?!?
如果用户不在他们的计算机前,这将不起作用。您可以上传存储在我的服务器目录中的照片吗?
到目前为止,这是我的代码。请记住,这不使用 facebook 会话,因为 access_code 已预先授予并存储。正如我所提到的,在用户墙上发布信息已经可以使用这种方法。
$filename= "@/myphotodir/filename.jpg");
$url = "https://graph.facebook.com/".$uid."/photos"; //$uid is fb user id
$ch = curl_init($url);
$attachment = array('access_token' => $access_token,
'app_id' => $app_id,
'name' => "A photo from me...",
'fileUpload' => true,
'message' => "my message",
'image' => $filename,
);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result= curl_exec($ch);
curl_close ($ch);
编辑:$结果返回错误...忘记添加。
任何帮助将不胜感激。 非常感谢, 院长
I've searched around everywhere without luck and found lots of examples to upload a photo to facebook when the user is in a session (i.e. the user is physically sitting at the computer and accessing the web page). I've tried the samples, and they work.
I noticed this unanswered question from last year on the same issue
Stackoverflow Question
My current app lets the user authorise off-line updates and I store the access_token, user_id, etc. and I can succesfully post to a users wall when they are offline.
I'm really struggling getting something to work with posting a photo to the users wall. Reading the Facebook documentation, I'm thinking you can only upload photos using multipart/form-data!?!?
That wouldn't work if the user isn't at their computer. Can you upload photos that are stored on a directory on my server?
Here's my code so far. Remember, this doesn't use a facebook session as the access_code has already been granted and stored beforehand. As I mentioned, posting to a users wall already works with this approach.
$filename= "@/myphotodir/filename.jpg");
$url = "https://graph.facebook.com/".$uid."/photos"; //$uid is fb user id
$ch = curl_init($url);
$attachment = array('access_token' => $access_token,
'app_id' => $app_id,
'name' => "A photo from me...",
'fileUpload' => true,
'message' => "my message",
'image' => $filename,
);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result= curl_exec($ch);
curl_close ($ch);
Edit: $result comes back false... forgot to add that.
Any help would be appreciated.
Many thanks,
Dean
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用 Facebook SDK。通过 Facebook SDK,您可以使用:
这会将照片发布到他们的默认相册。如果将 user_id 替换为 album_id,则可以发布到特定相册。
You should use the Facebook SDK. With the Facebook SDK, you can use:
This will post the photo to their default album. If you replace user_id with an album_id you can post to a specific album.