2012-06-21 6 views
1

페이스 북 이름과 그림을 동시에 가져 오는 데 문제가 있습니다. 나는 그 중 한 명만 각 요청을 할 수있다. (FBRequest *) 요청 didLoad : (ID (무효) 요청 - 내가 두 요청 Facebook 프로필 이름 및 사진 IOS 5.1

-(void)fbDidLogin{ 
    // Save the access token key info. 
    [self saveAccessTokenKeyInfo]; 

    // Get the user's info. 
    [facebook requestWithGraphPath:@"me/picture" andDelegate:self]; 
    [facebook requestWithGraphPath:@"me" andDelegate:self]; 
} 

와 같은과

으로 접근하는 경우

-(void)fbDidLogin{ 
    // Save the access token key info. 
    [self saveAccessTokenKeyInfo]; 

    // Get the user's info. 
    [facebook requestWithGraphPath:@"me/?fields=first_name,picture" andDelegate:self]; 

} 

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

    if ([result isKindOfClass:[NSArray class]]) { 

     result = [result objectAtIndex:0]; 

     if ([result objectForKey:@"first_name"]) { 
      [lblUser setText:[NSString stringWithFormat:@"Welcome %@!", [result objectForKey:@"first_name"]]]; 
      // Show the publish button. 
      [btnPublish setHidden:NO]; 
     } 
    } 
    else { 
     imageView.image = [UIImage imageWithData:result]; 
    }  
} 

오류는 내가

__NSCFDictionary length]: unrecognized selector sent to instance 
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary length]: unrecognized selector sent to instance 

를 얻을 수) 결과 오류가 발생했습니다

[__NSCFDictionary length]: unrecognized selector sent to instance 

그래서 페이스 북 이름과 그림을 요청하고 수신 데이터를 어떻게 처리 할 수 ​​있습니까?

답변

1

내가 코드가 페이스 북의 이름과 프로필 사진을 얻기 위해 잘 작동 다음, 그것을 고정

-(void)request:(FBRequest *)request didLoad:(id)result{ 
    // With this method we’ll get any Facebook response in the form of an array. 
    // In this example the method will be used twice. Once to get the user’s name to 
    // when showing the welcome message and next to get the ID of the published post. 
    // Inside the result array there the data is stored as a NSDictionary.  


    if ([result isKindOfClass:[NSData class]]) 
    { 
     NSLog(@"Profile Picture"); 
     imageView.image = [UIImage imageWithData:result]; 
     //[profilePicture release]; 
     //profilePicture = [[UIImage alloc] initWithData: result]; 
    } 


    if ([result isKindOfClass:[NSArray class]]) { 
     // The first object in the result is the data dictionary. 

     result = [result objectAtIndex:0]; 


    } 

    if ([result isKindOfClass:[NSDictionary class]]) { 
     // If the current result contains the "first_name" key then it's the user's data that have been returned. 
     // Change the lblUser label's text. 
     [lblUser setText:[NSString stringWithFormat:@"Welcome %@!", [result objectForKey:@"first_name"]]]; 
     // Show the publish button. 
     [btnPublish setHidden:NO]; 
    } 

} 
0

Facebook 서버가 제공하는 응답은 배열이 아닌 하나의 사전입니다. NSArray에 관한 두 줄을 제거하고 간단하게 사용

if ([result objectForKey:@"first_name"]) { 
     [lblUser setText:[NSString stringWithFormat:@"Welcome %@!", [result objectForKey:@"first_name"]]]; 
     NSLog(@"%@", lblUser); 
     // Show the publish button. 
     [btnPublish setHidden:NO]; 
} 
+0

난 페이스 북의 응답 난 그냥 변경 사전에 생각하지 말아 이것과 그것의 작품 if ([result isKindOfClass : [NSArray class]] –

관련 문제