【问题标题】:Get friends info from Facebook on my iPhone app在我的 iPhone 应用上从 Facebook 获取朋友信息
【发布时间】:2012-03-19 16:21:23
【问题描述】:

我正在开发一个使用 facebook 的 iPhone 应用程序。 我需要获取我的数据(当前用户的数据)。

我确定我进行了正确的登录并获得了适当的权限。

现在,

我想要一个带有数据的 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];

     }

有人可以帮我吗?

【问题讨论】:

    标签: iphone ios facebook


    【解决方案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];
    

    }

    【讨论】:

    • 感谢您的出色解决方案。我的代码的问题是返回的数据。我已经理解了这个方法的解决方案: - (void)request:(FBRequest *)request didLoad:(id)result { //Get a description of Result NSLog(@"\nDESCRIPTION: %@", [result description]) ; }
    • 不客气 .. 你可以通过接受答案在 SO 中说声谢谢 :)
    【解决方案2】:
              -(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];
        }
    }
    

    【讨论】:

      【解决方案3】:
      -(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"];
      }
      

      【讨论】:

        【解决方案4】:
        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];
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-08-04
          • 1970-01-01
          • 2011-05-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多