2011-05-30 49 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); 


     } 
    }]; 
} 

}

相關問題