How to update the profile cover photo using Graph API?

泄露秘密 提交于 2020-01-17 00:40:52

问题


There is an API support to update the cover photos for pages. Can I change my timeline cover photo using Facebook Graph API? There is a similar question in stack overflow click here. I have tried every solution in this question but I an unable to change the cover photo. I have used the method to update the page cover photo click here to see the documentation and this is the error

Fatal error: Uncaught OAuthException: (#10) Application does not have permission for this action


回答1:


After recent changes to Facebook api, we can only make cover photo of a page with photos which are in an album. We have to create an album and upload the photo to that album then we can use that photo as cover photo. Previously we can make cover from "photos of page's" album.

$args = array('name' => 'awesome album name', 'message' => 'awesome album message');
try {
    $album_id =$facebook->api("/$page_id/albums", 'post', $args);
}catch(Exception $e){
    echo $e->getMessage();
}

$args = array('image' =>'@'.realpath('/var/www/facebook.png'));
try{
    $uploaded_photo_details = $facebook->api("/{$album_id['id']}/photos", 'post', $args);
}catch(Exception $e){
    echo $e->getMessage();
}

if(isset($uploaded_photo_details['id'])){
$args = array('cover' => $uploaded_photo_details['id'], 'offset_y' =>0);
try {
    $cover_details = $facebook->api("/{$page_id}", 'post', $args);
}catch(Exception $e){
    echo $e->getMessage();
}

I wrote a complete tutorial about this http://blog.jambura.com/2012/12/05/change-facebook-pages-cover-photo-using-graph-api-and-page-api/



来源:https://stackoverflow.com/questions/17493384/how-to-update-the-profile-cover-photo-using-graph-api

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