我可以以某种方式获得比picture.data.url中返回的API更大的图像吗?
对于应用内朋友,我有userId我可以使用如下但是邀请朋友返回令牌而不是userId:
http://graph.facebook.com/{0}/picture?width={1}&height={2}
答案 0 :(得分:3)
当您调用Invitable friends API时,您可以使用类型或您自己的宽度和高度来缩放随附的图片。
对于预定义类型:
/me/invitable_friends?fields=picture.type(large)
对于你自己的宽度和高度:
/me/invitable_friends?fields=picture.width(150).height(150)
答案 1 :(得分:1)
也许这个例子会有所帮助:
FB.api('/me/invitable_friends?fields=picture.type(large)', function (response) {
// picture url will be in the response
}
图片类型位于此网址
https://developers.facebook.com/docs/graph-api/reference/v2.2/user/picture
答案 2 :(得分:0)
您可以修改invitable_friends的picture.data.url以访问更高质量的图像(可能是原始图像或至少与最初上传的图像相同的尺寸)。
示例:
删除域名和文件名之间的所有内容,即: https://fbcdn-profile-a.akamaihd.net/482877_10151573704436719_2137579306_n.jpg
一个简单的javascript函数会解析URL:
function GetFullImage(url){
var filename = url.replace(/^.*[\\\/]/, '');
return url.substring(0, url.indexOf("/",8)+1) + filename;
}
GetOriginalImage(friend.picture.data.url);
此外,您可以修改50x50部件以提供更大的尺寸,但这不是一个有保证的解决方案,因为:
1)较大的尺寸可能无法使用(用户可能上传了一张小图片)
2)裁剪信息(上例中为c62.62.780.780)可能只能在50x50时正确显示图像。 我确信这可能是一个直截了当的解决方案,可以达到你想要的尺寸,但我担心我还没有把所需的时间投入到这个中。希望上面的帮助无论如何。
答案 3 :(得分:0)
您可以修改invitable_friends的picture.data.url,以使用您自己的尺寸访问更高质量的图像。在这个Objective-C示例中,我们使用height = 120和weight = 120
#define IMAGE_PATTERN @"s120x120"
NSString *url_ = @"https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xpa1/v/t1.0-1/p50x50/1477386_637922472919990_2075386170_n.jpg?oh=afaeeb2448654c3ae05fb87d1a23b504&oe=54F2E920&__gda__=1424976270_d2b5b60376149424116b38783b0ddde0";
NSURL *url = [NSURL URLWithString:url_];
NSString *newUrl = [NSString stringWithFormat:@"%@://%@/%@/%@",
url.scheme,
url.host,
IMAGE_PATTERN,
url.pathComponents.lastObject];
NSLog(@"newUrl: %@", newUrl);