2012-05-02 28 views
2

我似乎無法使用當前的iOS圖形方法正確檢索用戶的個人資料圖片。沒有通過Graph API接收Facebook圖片

我的電話:self.pictureRequest = [facebook requestWithGraphPath:@"me/picture" andDelegate:self];

我做些什麼結果:

-(void)request:(FBRequest *)request didLoad:(id)result{ 
    if(request == self.pictureRequest){ 
     UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)]; 
     image.image = [UIImage imageWithData:result]; 
     [self.view addSubview:image]; 
     NSLog("result is %@", result); 
    } 

所以我只是想獲得的資料圖片現在。結果在控制檯中顯示爲空。我想這意味着我實際上沒有得到結果? (我試過if(result) NSLog(@"got a result"),但它不返回,所以我猜測結果不會被fb發回?)

任何想法?我也看了一個相似的問題在這裏,但不知道他們做了什麼不同: Problem getting Facebook pictures via iOS

回答

2

好,我就可以檢索用戶PIC等信息這樣的..嘗試

- (void)fetchUserDetails { 
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
            @"SELECT uid, name, pic, email FROM user WHERE uid=me()", @"query",nil]; 

    [fb requestWithMethodName:@"fql.query" 
            andParams:params 
           andHttpMethod:@"POST" 
            andDelegate:self]; 


}//Call this function after the facebook didlogin 

要求didLoad

- (void)request:(FBRequest *)request didLoad:(id)result 
{ 

    if([request.url rangeOfString:@"fql.query"].location !=NSNotFound) 
    { 
     if ([result isKindOfClass:[NSArray class]] && [result count]>0) { 
      result = [result objectAtIndex:0]; 
     } 
     if ([result objectForKey:@"name"]) { 

      self.fbUserName = [result objectForKey:@"name"]; 

      // Get the profile image 
      UIImage *fbimage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[result objectForKey:@"pic"]]]]; 
} 
0

您還可以通過FB資料圖片URL,

NSString *userFbId; 
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture", userFbId]]; 

NSData *imageData = [[NSData alloc] initWithContentsOfURL:url]; 
self.userProfileImage.image = [UIImage imageWithData:imageData]; 
相關問題