问题描述
|
我正在通过URL从Facebook获取图像:http://external.ak.fbcdn.net/safe_image.php?d=d282e1e7c86c9270232f97ddc737df39&w=90&h=90&url=http%3A%2F%2Fi52.tinypic.com%2F2q0ixzl.jpg
现在,我想要一个更大的版本,例如200 x200。是否有相应的网址?如果没有,如何将图像转换为更大的尺寸?
解决方法
通常,如果您要收集用户或页面的个人资料图片,则图标大小图片的格式为:
http://graph.facebook.com/[page id/profile id]/picture
对于大图:
http://graph.facebook.com/[page id/profile id]/picture?type=large
编辑要点:
如果存储在facebook服务器上的图像小于200 * 200尺寸,则将获得可用的最高分辨率图像,例如:128 * 160。您可以使用GD库来调整它的大小。
还有一件事情
Facebook支持200 * 600px作为个人资料图片的最高分辨率。它将通过保持纵横比来调整图像大小以适合这些尺寸。
*更新于2017年2月19日*
我们需要使用这种新的URL格式来获取所需的个人资料图片。
http://graph.facebook.com/{profile_id}/picture?width={number}&height={number}
[谢谢https://stackoverflow.com/users/2829128/vay]
, 如果您想获得更大的图片,则可以像这样设置高度和宽度:
http://graph.facebook.com/[page id/profile id]/picture?width=[number]&height=[number]
更多信息和示例在这里:图片-Facebook开发人员
, 这也将工作
picture.type(大)
例
if ([FBSDKAccessToken currentAccessToken]) {
[[[FBSDKGraphRequest alloc] initWithGraphPath:@\"me\" parameters:@{@\"fields\": @\"picture.type(large),name,email\"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,id result,NSError *error) {
if (!error) {
NSLog(@\"fetched user:%@\",result);
NSMutableDictionary *data=[[NSMutableDictionary alloc]init];
data=result;
fbId.text=[data valueForKey:@\"id\"];
userName.text=[data valueForKey:@\"name\"];
_emailFB.text=[data valueForKey:@\"email\"];
NSDictionary *dictionary = (NSDictionary *)result;
NSDictionary *data3 = [dictionary objectForKey:@\"picture\"];
NSDictionary *data2 = [data3 objectForKey:@\"data\"];
NSString *photoUrl = (NSString *)[data2 objectForKey:@\"url\"];
NSLog(@\"Photo : %@\",photoUrl);
}
}];
}
}
, 是的,有一种方法可以获取facebook页面的原始(通常是更大的)个人资料图片。
其实答案已经在问题中了。原始图像URL已嵌入在save_image URL中。您的情况是\“ url = http%3A%2F%2Fi52.tinypic.com%2F2q0ixzl.jpg”表示\“ http://i52.tinypic.com/2q0ixzl.jpg \”
就我而言,伦敦的页面是
https://www.facebook.com/pages/London-United-Kingdom/106078429431815?fref=ts
我可以通过搜索关键字London轻松获得其fb对象ID。
我尝试使用width和height参数。它们可用于用户个人资料图片或用户共享图片,但不能用于公共页面个人资料图片。
https://graph.facebook.com/106078429431815/picture?width=300&height=300 // can’t work
我可以通过以下仅180x77的网址获得最大的图片
https://graph.facebook.com/106078429431815/picture?type=large
但是我可以使用fb graph api获取safe_image.php网址,并且原始图片网址也位于参数的url部分中
\"url\": \"https://fbexternal-a.akamaihd.net/safe_image.php?d=AQCrtKykRotXBuaS&w=180&h=540&url=http%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2Fthumb%2Farchive%2F2%2F21%2F20141005220235%2521City_of_London_skyline_at_dusk.jpg%2F720px-City_of_London_skyline_at_dusk.jpg&fallback=hub_city&prefix=d\"
这是我使用的代码。
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@\"/%@/picture?redirect=false&type=large\",[firstCityPage objectForKey:@\"id\"]]
completionHandler:^(
FBRequestConnection *connection,NSError *error
) {
NSString *profileImgUrl = [NSString stringWithFormat:@\"http://graph.facebook.com/%@/picture?type=large\",[firstCityPage objectForKey:@\"id\"]];
if (error==nil) {
NSString *fbSaveImgUrl = [[(NSDictionary*)result objectForKey:@\"data\"] objectForKey:@\"url\"];
NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:[NSURL URLWithString:fbSaveImgUrl]
resolvingAgainstBaseURL:NO];
for (NSURLQueryItem *queryItem in urlComponents.queryItems) {
if ([queryItem.name isEqualToString:@\"url\"]) {
profileImgUrl = queryItem.value;
break;
}
}
} else {
NSLog(@\"%@\",[error description]);
}
NSLog(@\"url: %@\",profileImgUrl);
...
}];
但是,存在风险。
不保证外部图像的URL将被验证。
Facebook将来可能会删除safe_image URL中的显式外部URL或向开发人员隐藏safe_image URL。
需要您自担风险使用它。