Upload image to Facebook Wall / Feed via Graph API

回眸只為那壹抹淺笑 提交于 2019-12-06 09:56:43

问题


I am trying to upload local images directly to a pages feed (i.e. "Wall Photos" album).

This is the code that I think should work:

<?php
$facebook = new Facebook(array(
    'appId'  => $the_app_id,
    'secret' => $this_app_secret,
));
$facebook->setAccessToken($the_access_token);
$facebook->setFileUploadSupport(true);

$attachment = array(
    'message' => $the_post_body,
    'name' => $this_image_name,
    'picture' => '@' . $the_absolute_path_to_image
);

$result = $facebook->api('/me/feed, 'post', $attachment);

But this code just yields a plain text wall post with the contents of "message" (i.e. picture field is seemingly ignored). I have also tried "/page_id/feed", same result.

Now, simply changing the endpoint to "/me/photos", does upload the photo to a 'normal' album with the name of the app, but I want it to look as much like a normal post as possible and so hence into the "Wall Photos" album).

I realise that I could achieve this by querying the graph with FQL to find the object_id of the "Wall Photos" album, but if it does not exist it would require extra permissions to create it and I would rather keep permissions as simple as possible.

If anyone could point out how to upload photos to "/me/feed" I would greatly appreciate it.


回答1:


But this code just yields a plain text wall post with the contents of "message" (i.e. picture field is seemingly ignored). I have also tried "/page_id/feed", same result.

You can only give the link to picture but not the data.

Now, simply changing the endpoint to "/me/photos", does upload the photo to a 'normal' album with the name of the app, but I want it to look as much like a normal post as possible and so hence into the "Wall Photos" album).

Ye, it creates an album by default based on app. if already exists, it uploads to album. And generates a post.

I realise that I could achieve this by querying the graph with FQL to find the object_id of the "Wall Photos" album, but if it does not exist it would require extra permissions to create it and I would rather keep permissions as simple as possible.

You cannot upload to fb for me/feed end point. You should store in your server/s3/some service and give the public url to me/feed params.



来源:https://stackoverflow.com/questions/10897817/upload-image-to-facebook-wall-feed-via-graph-api

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