使用Facebook iOS SDK检索生日

use*_*946 1 iphone xcode facebook-graph-api ios

我刚开始使用API​​,所以我不确定如何正确执行它.

我想要获得用户朋友的所有生日.到目前为止,我成功获得了他们的friendList,然后理论上我可以简单地ping每个ID并从中获取生日.

但是我不确定如何实现这些方法.

当我的viewController加载时: [facebook requestWithGraphPath:@"me/friends" andDelegate:self];

这将发送请求,我实现FBRequestDelegate方法来接收它:

-(void)request:(FBRequest *)request didLoad:(id)result{
    NSLog(@"result is : %@", result);
}
Run Code Online (Sandbox Code Playgroud)

到目前为止工作完美,我得到一个包含所有朋友姓名和ID的对象.但是,现在我想遍历每个ID,并发送另外几百个请求.我已经知道如何设置循环和请求调用,但我已经在这个viewController中使用了didLoad方法,显然我需要在返回数据对象后以不同方式处理数据.

与(FBRequest*)有关?那是什么,也许我可以去if(request == something)?谢谢

And*_*sek 8

您可以使用单个fql请求检索您(或用户)的facebook好友的生日.

你可以在这里阅读关于fql:http://developers.facebook.com/docs/reference/fql/

但这里有一些代码供参考(此代码在一个定义为FBSessionDelegate和FBRequestDelegate的类中)

- (void)request:(FBRequest *)request didLoad:(id)result {
    // result is a NSDictionary of your friends and their birthdays!
}

- (void)fbDidLogin {
    //some best practice boiler plate code for storing important stuff from fb
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];

    //now load all my friend's birthdays
    NSMutableDictionary * params = 
                         [NSMutableDictionary dictionaryWithObjectsAndKeys:
                         @"select birthday, name, uid, pic_square from user where uid in (select uid2 from friend where uid1=me()) order by name", 
                         @"query",
                         nil];

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

- (void) loginWithFacebook {
    self.facebook = [[[Facebook alloc] initWithAppId:@"<your app id here>" andDelegate:self] autorelease];
    //IMPORTANT - you need to ask for permission for friend's birthdays
    [facebook authorize:[NSArray arrayWithObject:@"friends_birthday"]];
}
Run Code Online (Sandbox Code Playgroud)