我目前正在使用 the Graph API Explorer 进行一些测试。这是一个很好的工具。
我想获取用户的好友列表,包括好友的姓名、ID 和图片。所以我输入:
https://graph.facebook.com/me/friends?fields=id,picture,name
但是图片只有 50x50,我想要一个更大的这个请求。
可能吗 ?
如 Facebook 上的 this bug 中所述,您现在还可以通过新的 API“field expansion”语法请求特定的图像尺寸。
像这样:
https://graph.facebook.com/____OBJECT_ID____?fields=picture.type(large)
让所有朋友(当然也使用该应用程序)获得正确图片尺寸的最佳方法是使用 field expansion,或者使用尺寸标签之一(方形、小、正常、大):
/me/friends?fields=picture.type(large)
(编辑:这不再起作用了)
...或者您可以指定宽度/高度:
me/friends?fields=picture.width(100).height(100)
顺便说一句,你也可以这样写:
me?fields=friends{picture.type(large)}
不过,您不需要拉“图片”属性。还有更方便的方法,您唯一需要的是用户名,请参见下面的示例;
https://graph.facebook.com/user_id/picture?type=large
ps 类型定义你想要的大小
请记住,使用具有基本权限的令牌,/me/friends 将仅返回具有 id+name 属性的朋友列表
您可以以像素为单位设置图片的大小,如下所示:
https://graph.facebook.com/v2.8/me?fields=id,name,picture.width(500).height(500)
以类似的方式,可以使用 type
参数
{user-id}/?fields=name,picture.type(large)
类型枚举{小,正常,专辑,大,方形}
将字段数组 id,name,picture
更改为 id,name,picture.type(large)
https://graph.facebook.com/v2.8/me?fields=id,name,picture.type(large)&access_token=<the_token>
结果:
{
"id": "130716224073524",
"name": "Julian Mann",
"picture": {
"data": {
"is_silhouette": false,
"url": "https://scontent.xx.fbcdn.net/v/t1.0-1/p200x200/15032818_133926070419206_3681208703790460208_n.jpg?oh=a288898d87420cdc7ed8db5602bbb520&oe=58CB5D16"
}
}
}
Graph returned an error: (#100) For field 'picture': type must be one of the following values: thumbnail, small, album
如果需要,您也可以尝试根据高度或宽度获取图像
https://graph.facebook.com/user_id/picture?height=
或者
https://graph.facebook.com/user_id/picture?width=
默认情况下,这些值以像素为单位,您只需要提供 int 值
我广泛研究了 Graph API Explorer 并最终找到了 full_picture
https://graph.facebook.com/v2.2/$id/posts?fields=picture,full_picture
PS 我注意到 full_picture 并不总是提供我想要的全尺寸图像。 “附件”确实
https://graph.facebook.com/v2.2/$id/posts?fields=picture,full_picture,attachments
嗯……我想我找到了解决办法。
事实上,in 可以只是请求
https://graph.facebook.com/me/friends?fields=id,name
根据http://developers.facebook.com/docs/reference/api/(“图片”部分),可以使用用户 ID 构建个人资料照片的 url
例如,假设用户 id 在 $id 中:
"http://graph.facebook.com/$id/picture?type=square"
"http://graph.facebook.com/$id/picture?type=small"
"http://graph.facebook.com/$id/picture?type=normal"
"http://graph.facebook.com/$id/picture?type=large"
但这不是最终的图像 URL,所以如果有人有更好的解决方案,我会很高兴知道 :)
您可以指定 width
& height
在您对 Facebook 图形 API 的请求中:http://graph.facebook.com/user_id/picture?width=500&height=500
从 v2.7
,/<picture-id>?fields=images
将为您提供一个包含不同大小图像的列表,第一个元素是完整大小的图像。
我不知道一次处理多个图像的任何解决方案。
当我向 picture.type(full_picture)
发出请求时出现此错误:
“(#100)对于字段'图片':类型必须是以下值之一:小,正常,相册,大,方形”
当我使用 picture.type(album)
和 picture.type(square)
发出请求时,以 50x50 像素大小的图像响应我。
当我使用 picture.type(large)
发出请求时,以 200x200 像素大小的图像响应我。
当我使用 picture.width(800)
发出请求时,以 477x477 像素大小的图像响应我。
使用 picture.width(250)
,响应 320x320。
使用 picture.width(50)
,响应 50x50。
使用 picture.width(100)
,响应 100x100。
使用 picture.width(150)
,响应 160x160。
我认为当用户第一次添加该照片时,facebook 会给出不同大小的图像。
我在这里看到的用于请求用户图像的 API 不支持调整请求的图像大小。我认为它给出了最接近的图像尺寸。
您可以按如下方式调整其大小。
利用:
https://graph.facebook.com/USER_ID?fields=picture.type(large)
详情:https://developers.facebook.com/docs/graph-api/reference/user/picture/
在图表响应(“http://photos-c.ak.fbcdn.net/”)中找到的图片 URL 中,只需将默认的“_s.jpg”替换为“_n.jpg”(?正常大小)或“_b.jpg”(?大尺寸)或“_t.jpg”(缩略图)。
Hacakable URLs/REST API 让 Web 变得更好。
rest-fb 用户(方形图像,更大分辨率): Connection myFriends = fbClient.fetchConnection("me/friends", User.class, Parameter.with("fields", "public_profile,email,first_name,last_name,gender,picture .width(100).height(100)"));
我认为到目前为止,获得朋友大照片的唯一方法是使用 FQL。首先,您需要获取朋友列表:
https://graph.facebook.com/me/friends
然后解析此列表并提取所有朋友 ids
。当你拥有它时,只需执行以下 FQL 查询:
SELECT id, url FROM profile_pic WHERE id IN (id1, id2) AND width=200 AND height=200
200
这里只是一个示例尺寸,您可以输入任何内容。您应该得到以下响应:
{
"data": [
{
"id": ...,
"url": "https://fbcdn-profile-a.akamaihd.net/..."
},
{
"id": ...,
"url": "https://fbcdn-profile-a.akamaihd.net/..."
}
]
}
每个网址都是指向 200x200 像素图像的链接。
我有同样的问题,但我尝试了这个来解决我的问题。它返回大图像。这不是完美的修复,但你可以试试这个。
https://graph.facebook.com/v2.0/OBJECT_ID/picture?access_token=XXXXX
尝试通过更改每个 json 对象中 url 的像素大小来更改图像的大小,如下所示:
例如,我将 s480x480 更改为 s720x720
JS 风格的变体。只需设置巨大的大图片宽度,您将获得最大的变体。
FB.api(
'/' + userId,
{fields: 'picture.width(2048)'},
function (response) {
if (response && !response.error) {
console.log(response.picture.data.url);
}
}
);
您可以使用 full_picture 代替图片键来获取全尺寸图像。
注意:从 Graph API v8.0 开始,您must provide the access token
针对您所做的每个 UserID 请求。
命中图形 API:
https://graph.facebook.com/<user_id>/picture?height=1000&access_token=<any_of_above_token>
使用火力基地:
FirebaseUser user = mAuth.getCurrentUser();
String photoUrl = user.getPhotoUrl() + "/picture?height=1000&access_token=" +
loginResult.getAccessToken().getToken();
您可以像这样从 registerCallback
获取令牌
LoginManager.getInstance().registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
FirebaseUser user = mAuth.getCurrentUser();
String photoUrl = user.getPhotoUrl() + "/picture?height=1000&access_token=" + loginResult.getAccessToken().getToken();
}
@Override
public void onCancel() {
Log.d("Fb on Login", "facebook:onCancel");
}
@Override
public void onError(FacebookException error) {
Log.e("Fb on Login", "facebook:onError", error);
}
});
这就是文档所说的:
从 2020 年 10 月 24 日开始,所有基于 UID 的查询都需要访问令牌。如果您查询 UID 并因此必须包含令牌: 对 Facebook 登录身份验证请求使用用户访问令牌 对页面范围请求使用页面访问令牌 对服务器端请求使用应用程序访问令牌 对移动设备或客户端访问令牌使用客户端访问令牌Web 客户端请求 如果您无法使用其他令牌类型之一,我们建议您仅使用客户端令牌。
不定期副业成功案例分享