2011-05-30 51 views
18

我对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如何获得一个Facebook页面

现在,我希望有一个更大的版本,像200 200是否有一个网址?如果没有,我怎样才能将这个图像转换成更大的尺寸?

+0

这是一个档案相片吗? – 2011-05-30 13:18:18

+0

是的,它是.......... – PJR 2011-05-30 13:19:47

+0

只是通过设置图片的宽度和高度 – 2011-05-30 13:21:10

回答

52

一般来说,如果你要收集用户或页面的个人资料相片,为图标大小的图片格式为:

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的作为档案相片最高分辨率。它将通过保持高宽比来调整图像的大小以适应这些尺寸。

* UPDATE作为2017年2月19日*

我们需要使用这个新的URL形成以获得所需形状的图像。

http://graph.facebook.com/[page id/profile id]/picture?width=[number]&height=[number] 

更多信息和例子在这里:

http://graph.facebook.com/{profile_id}/picture?width={number‌​}&height={number} 

[如果你想获得你可以设置高度图片放大和宽度你想这样感谢您https://stackoverflow.com/users/2829128/vay]

+0

@PJR - 请您标记答案为正确的使其他人更容易从未来的这个问题中获得帮助。谢谢。 – 2011-05-31 04:14:50

+0

是否有另一种方式获得比200 * 600更大的图像? – 2011-09-21 11:18:22

+0

非常感谢,非常有用 我一直在寻找这个解决方案,非常感谢 – Muhammed 2012-01-18 22:47:39

23
+2

这应该是答案,恕我直言。 – silent 2015-04-20 09:24:36

+1

谢谢,对我有用 – 2015-08-12 17:16:42

+0

应该是公认的答案!谢谢。 – AlexioVay 2017-02-04 22:36:13

0

是的,有一种方法可以获取Facebook页面的原始(大部分时间更大)的个人资料图片。

其实答案已经在问题中了。原始图片网址已嵌入到save_image网址中。你的情况是“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 

我可以很容易地搜索关键字伦敦获得其FB对象ID。 我曾尝试使用宽度和高度参数,它们与用户的个人资料图片或用户共享照片的工作,但不能与公共页面的个人资料图片工作。

https://graph.facebook.com/106078429431815/picture?width=300&height=300 // can’t work 

我可以通过以下网址获取它的最大图片小时只是180x77

https://graph.facebook.com/106078429431815/picture?type=large 

但我可以得到safe_image。通过使用fb图形api和原始图像url也在参数的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, 
             id result, 
             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); 

         ... 
        }]; 

但是,有风险。

  1. 不保证外部图像的URL将被验证。

  2. Facebook可能会删除safe_image url中的显式外部url或将来从developer中隐藏safe_image url。

使用它需要您自担风险。

6

这也将工作

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); 


     } 
    }]; 
} 

}

相关问题