2012-03-19 108 views
0

我正在爲使用Facebook的iPhone開發應用程序。 我需要獲取我的數據(當前用戶的數據)。在我的iPhone應用程序上從Facebook獲取朋友信息

我確定我做了正確的登錄並獲得了適當的權限。

現在,

我想用數據的NSArray並與NSLog的哦,這個數據的打印。

我做這個的好友列表和我有沒有問題:

-(IBAction)friendsInfo:(id)sender{ 

    // get the logged-in user's friends 
    [facebook requestWithGraphPath:@"me/friends" andDelegate:self]; 

    } 

- (void)request:(FBRequest *)request didLoad:(id)result { 
    //ok so it's a dictionary with one element (key="data"), which is an array of dictionaries, each with "name" and "id" keys 
    items = [(NSDictionary *)result objectForKey:@"data"]; 
    for (int i=0; i<[items count]; i++) { 
     NSDictionary *friend = [items objectAtIndex:i]; 
     long long fbid = [[friend objectForKey:@"id"]longLongValue]; 
     NSString *name = [friend objectForKey:@"name"]; 
     NSLog(@"id: %lld - Name: %@", fbid, name); 
    } 
} 

但對於我的信息相同的方法行不通:

-(IBAction)myInfo:(id)sender{ 

    // get information about the currently logged in user 
    [facebook requestWithGraphPath:@"me" andDelegate:self]; 

    } 

有人能幫助我嗎?

回答

1

使用此功能,讓您的Facebook信息(登錄的用戶信息)

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

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

}

+0

感謝你們給我很好的解決方案。我的代碼的問題是返回的數據。我已經理解了這個方法的解決方案: - (void)request:(FBRequest *)request didLoad:(id)result {獲取結果的描述 NSLog(@「\ nDESCRIPTION:%@」,[result描述]); } – Byteros 2012-03-21 13:01:42

+0

歡迎您..您可以通過接受答案來說聲謝謝:) – 2012-03-21 13:42:42

0
-(IBAction)getMeFriendsButtonPressed:(id)sender { 
    FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:@"me/friends" withGetVars:nil]; 
    NSLog(@"getMeFriendsButtonPressed: %@", fb_graph_response.htmlResponse); 

    NSDictionary *DictTmp = [fb_graph_response.htmlResponse JSONValue]; 
    NSMutableArray *myFriendList=[[DictTmp objectForKey:@"data"]; 
} 
0
NSString* fql = [NSString stringWithFormat:@"select uid,name from user where uid == %lld", session.uid]; 

NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:@"query"]; 
[[FBRequest requestWithDelegate:self] call:@"facebook.fql.query" params:params]; 
[[FBRequest requestWithDelegate:self] call:@"facebook.friends.get" params:params]; 
1
  -(void)addList:(FBSession *)session { 
    NSString* fql = [NSString stringWithFormat: 
        @"select uid from user where uid == %lld", session.uid]; 

    NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:@"query"]; 
    sessionView = session; 
    [[FBRequest requestWithDelegate:self] call:@"facebook.friends.get" params:params]; 


} 

     - (void)request:(FBRequest*)request didLoad:(id)result { 
    if(myList==nil) { 
     NSArray* users = result; 
     myList =[[NSArray alloc] initWithArray: users]; 
     for(NSInteger i=0;i<[users count];i++) { 
      NSDictionary* user = [users objectAtIndex:i]; 
      NSString* uid = [user objectForKey:@"uid"]; 
      NSString* fql = [NSString stringWithFormat: 
         @"select name from user where uid == %@", uid]; 

      NSDictionary* params = [NSDictionary dictionaryWithObject:fql   forKey:@"query"]; 
      [[FBRequest requestWithDelegate:self] call:@"facebook.fql.query"  params:params]; 
     } 
    } 
    else { 
     NSArray* users = result; 
     NSDictionary* user = [users objectAtIndex:0]; 
     NSString* name = [user objectForKey:@"name"]; 
     txtView.text=[NSString  localizedStringWithFormat:@"%@%@,\n",txtView.text,name]; 
    } 
} 
相關問題