簡體   English   中英

使用3.0 SDK獲取Facebook個人資料照片

[英]Get Facebook profile pic using 3.0 SDK

我無法使用新的Facebook SDK獲取用戶的個人資料照片。 這里的所有答案都使用舊SDK中不再有效的方法。

我已經嘗試過使用Facebook教程中推薦的FBProfilePictureView,但是這張圖片沒有被緩存,我認為它不能轉換成UIImage。

有人可以提供一些幫助嗎? 謝謝!

好的,我終於使用以下內容得到了這個:

imageData = [[NSMutableData alloc] init]; // the image will be loaded in here
NSString *urlString = [NSString stringWithFormat:@"http://graph.facebook.com/%@/picture?type=large", user.id];
NSMutableURLRequest *urlRequest =
[NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]
                                     cachePolicy:NSURLRequestUseProtocolCachePolicy
                                 timeoutInterval:2];

// Run request asynchronously
NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest:urlRequest
                                                                              delegate:self];
if (!urlConnection)
        NSLog(@"Failed to download picture");

然后我使用-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data-(void)connectionDidFinishLoading:(NSURLConnection *)connection將圖像放在一起。

我發現最好的解決方案:我使用過AFNetworking的UIImage https://github.com/AFNetworking/AFNetworking 它處理重定向和緩存,因此您可以為您擁有的每個用戶ID獲取個人資料圖片。

NSString *imageUrl = [NSString stringWithFormat:@"http://graph.facebook.com/%@/picture", ((NSDictionary<FBGraphUser> *) [self.friends objectAtIndex: indexPath.row]).id];
[friendCell.imageView setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@"profile.jpg"]];

使用https://github.com/rs/SDWebImage緩存圖像。 請求圖像的URL應該是

NSString *string = [NSString stringWithFormat:@"https://graph.facebook.com/%@?fields=picture", userid];

使用鏈接:

  https://graph.facebook.com/me?fields=picture 

獲取當前用戶的個人資料圖片。

Facebook提供了Graph API資源管理器工具 ,當您想要嘗試查詢或檢查返回的輸出時,它可以派上用場。

這是User API Reference的鏈接。

如果您的問題與“self.userPofilePicture.profileID = user.id;”有關。

然后self.userProfilePicture返回UIView,所以只需要查看並顯示在其中。

不要忘記在Identity Inspector中添加類FBProfilePictureView以及將[FBProfilePictureView類]添加到AppDelegate實現文件中。

我希望這會有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM