Getting Facebooks' Cover Photo via PHP SDK & G

2019-02-04 19:55发布

I'd like to know if there is a simple way of retrieving the Cover photo from a user in my application, via the facebook php sdk.

Thanks in advance.

13条回答
一夜七次
2楼-- · 2019-02-04 20:37

I use username instead of id and it works:

http://graph.facebook.com/{username}?fields=cover

Parse the JSON accordingly.

查看更多
Anthone
3楼-- · 2019-02-04 20:40

Facebook seems to have added the Cover field to User Object recently

https://graph.facebook.com/facebookuserid?fields=cover will give you the user cover pic Details

Facebook Doc Link : http://developers.facebook.com/docs/reference/api/user/

查看更多
兄弟一词,经得起流年.
4楼-- · 2019-02-04 20:40

Facebook has a really poor and outdated documentation... At the moment there isn't a proper way to do this via Graph API, but with FQL it is possible.

SELECT pic_cover FROM user WHERE uid='yourUserId'

The field pic_cover isn't documented but available. The response should look like this:

[
 {
  "pic_cover": {
   "cover_id": someId,
   "source": "someUrl",
   "offset_y": someOffset
  }
 }
]
查看更多
做自己的国王
5楼-- · 2019-02-04 20:40
function getCover() {
    FB.api('/me?fields=cover', function(response) {
       document.getElementById('cover').innerHTML =
          "<img src='" + response.cover['source'] + "' alt='' />"

    });
}
查看更多
▲ chillily
6楼-- · 2019-02-04 20:41

it tries to automatically recover from the image through php

$json = file_get_contents("https://graph.facebook.com/PROFILE_ID?fields=cover");
$obj = json_decode($json);
echo $obj->cover ->source;
查看更多
Viruses.
7楼-- · 2019-02-04 20:44

The latest versions of Graph API (2.4 is current at the time of writing) support 'picture' field that returns user's profile picture. It's worth checking.

/<user-id>?fields=id,name,picture
查看更多
登录 后发表回答