简体   繁体   English

获取Facebook用户个人资料图片,而无需他们登录到Facebook

[英]Get Facebook user profile picture without them being logged into Facebook

In my database some users have Facebook IDs stored, as once they logged into my website via Facebook. 当他们通过Facebook登录到我的网站时,某些用户在我的数据库中存储了Facebook ID。 For each of those users I would like to store a profile picture, which would be retrieved from their Facebook accounts. 对于这些用户,我想存储一个个人资料图片,可以从他们的Facebook帐户中检索该图片。

Facebook PHP SDK specifies the following way to get a user picture: Facebook PHP SDK指定了以下获取用户图片的方式:

/* PHP SDK v4.0.0 */
/* make the API call */
$request = new FacebookRequest(
  $session,
  'GET',
  '/me/picture'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */

The problem is the $session param. 问题是$session参数。 Currently, I get the FacebookSession object after the user logs into my website via Facebook. 当前,当用户通过Facebook登录到我的网站后,我得到了FacebookSession对象。 However, for what I want to achieve, I don't have the session present. 但是,对于我想要实现的目标,我没有参加本次会议。

Is it possible in PHP SDK to get Facebook user profile picture when having only the user ID, and without them being logged into Facebook? 在只有用户ID且没有将他们登录到Facebook的情况下,PHP SDK是否可以获取Facebook用户个人资料图片?

I hope this helps, 我希望这有帮助,

http://graph.facebook.com/USERNAME OR USERID/picture?type=large

http://graph.facebook.com/USERNAME OR USERID/picture?type=small http://graph.facebook.com/USERNAME OR USERID/picture?type=square http://graph.facebook.com/USERNAME或USERID / picture?type = small http://graph.facebook.com/USERNAME或USERID / picture?type = square

You do not need to log into facebook just use USERNAME OR USERID. 您无需使用USERNAME或USERID登录Facebook。 This is simple, basic thing and require only Googling... If you're not looking for this, please elaborate the task you're doing... 这是简单,基本的事情,只需要使用Google搜索就可以了。如果您不打算这样做,请详细说明您正在执行的任务...

Good Luck!!! 祝好运!!!

Simply use the following Graph path via GET request: 只需通过GET请求使用以下Graph路径:

/{user_id}?fields=picture.type(large),id,name

Field type can be one of the following values: 字段类型可以是以下值之一:

  • small
  • normal 正常
  • large
  • square 广场

Or using width and/or height value like this: 或使用像这样的宽度和/或高度值:

/{user_id}?fields=picture.width(200).height(200),id,name

Also you can add redirect=0 param. 您也可以添加redirect = 0参数。 By default the picture edge will return a picture instead of a JSON response. 默认情况下,图片边缘将返回图片而不是JSON响应。 If you want the picture edge to return JSON that describes the image set redirect=0 when you make the request. 如果您希望图片边缘在发出请求时返回描述图像集的JSON的JSON,则JSON = 0。

So you will have the following JSON response: 因此,您将获得以下JSON响应:

{
  "picture": {
    "data": {
      "height": 120,
      "is_silhouette": false,
      "url": "https://scontent.xx.fbcdn.net/hprofile-xaf1/v/t1.0-1/c53.10.120.120/165675_138088076251005_752993_n.jpg?oh=a9450bf53f2d2294531e11ae28be99c1&oe=56C740A5",
      "width": 120
    }
  },
  "id": "138087416251071",
  "name": "Zenonis",
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM