Setting Facebook Cover Photo via API [closed]

2020-05-19 07:28发布

问题:

Is there a way to get and set the new cover photo on the Facebook timeline profile via the API?

回答1:

There´s no API support for changing user profile cover, but you can upload a photo and then redirect user to: http://www.facebook.com/profile.php?preview_cover=PHOTO_ID



回答2:

There is an API for updating the cover photo on a page

http://developers.facebook.com/docs/reference/api/page/

It asks for a photo id which I guess is the id of a photo from the users album. I am trying to update the photo, though think that first need to update that photo in album to retrieve the photo id



回答3:

You can get the picture via the regular photo APIs (it's in the 'Cover Photos' album) and also in the cover field of the User object - a sample call being /me?fields=cover to retrieve it.

There's no API to set the User cover photo and I'm not aware of any plans to add one.

Pages' cover photos can be edited using the API - see the Pages API documentation for more information - you make a POST request to /PAGE_ID?cover=<ID of a photo in the page's album> with the Page access token



回答4:

$user_id = $facebook->getUser();

if($user_id == 0 || $user_id == "")
{
    $login_url = $facebook->getLoginUrl(array(
    'redirect_uri'         => 'http://yoursite.com/upload.php?coverid='xxxxxx',
    'scope'      => "publish_stream,user_photos,user_photo_video_tags,user_videos"));

    echo "<script type='text/javascript'>top.location.href = '$login_url';</script>";
    exit();
}

//get profile album
$albums = $facebook->api("/me/albums");
$album_id = ""; 
foreach($albums["data"] as $item){
    if($item["type"] == "cover_photo"){
        $album_id = $item["id"];
        break;
    }
}