开发者

How to post photos into the album of Facebook page(fanpage) using API?

开发者 https://www.devze.com 2023-04-02 12:18 出处:网络
I\'m building a Facebook page as administrator. And developing some apps using PHP and Facebook API. What I\'d like to do is to upload photos into the specified album on the Facebook page.

I'm building a Facebook page as administrator. And developing some apps using PHP and Facebook API. What I'd like to do is to upload photos into the specified album on the Facebook page. At this moment, I've got following error message after posting into the album_id.

"error": { "type": "OAuthException", "message": "(#120) Invalid album id"

Then, I'd like to know follofing things. How to get the access_token for开发者_如何学运维 the Facebook page not for me. The permissions (user_photos,publish_stream,manage_pages,photo_upload) are enough? Finally, if you have some experience, please show me the successful sample code?


To get the access token for the page, try this:

$page_token_url = "https://graph.facebook.com/" . 
  $page_id . "?fields=access_token&" . $access_token;
$response = file_get_contents($page_token_url);
$resp_obj = json_decode($response,true);
$page_access_token = $resp_obj['access_token'];

For permissions publish_stream and manage_pages are enough.

For actually posting the image, I'm doing this (which works):

$ch = curl_init("https://graph.facebook.com/$album_id/photos/");  
curl_setopt($ch, CURLOPT_POSTFIELDS,
    array('access_token'=>$page_access_token,
    'source'=>"@$filename",
    'message'=>$caption,
    'description'=>$message));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$rtn = curl_exec($ch);
curl_close($ch);
echo $rtn;
0

精彩评论

暂无评论...
验证码 换一张
取 消