使用Facebook iOS SDK检索生日 [英] Using Facebook iOS SDK to retrieve birthdays

查看:222
本文介绍了使用Facebook iOS SDK检索生日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来使用API​​,所以我不知道如何正确执行这个。



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



然而,我不确定如何实现方法。



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



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

   - (void)request:(FBRequest *)request didLoad:(id)result {
NSLog(@result is:%@,result);
}

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


与$(FBRequest *)有关的事情?这是什么,也许我可以去像(请求==的东西)?感谢

解决方案

您可以通过单个fql请求检索您(或用户的)facebook朋友的生日。



您可以在这里阅读有关fql的信息: http:// developers.facebook.com/docs/reference/fql/



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

   - (void)请求:(FBRequest *)请求didLoad:(id)result {
/ /结果是你的朋友和他们的生日的NSDictionary!
}

- (void)fbDidLogin {
//一些最佳做法锅炉板代码,用于存储重要的东西从fb
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@FBAccessTokenKey];
[defaults setObject:[facebook expirationDate] forKey:@FBExpirationDateKey];
[默认同步];

//现在加载所有我朋友的生日
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.queryandParams:params andHttpMethod:@POSTandDelegate:self];
}

- (void)loginWithFacebook {
self.facebook = [[[分配] initWithAppId:@<你的应用程序ID在这里>自动释放];
//重要 - 您需要向朋友的生日请求许可
[Facebook授权:[NSArray arrayWithObject:@friends_birthday]];
}


I'm new to using API's, so I'm not sure how to properly execute this.

I'm trying to get all the birthdays of a user's friends. So far I am successful in getting their friendList, and then in theory I can simply ping each ID and get the birthday from it.

However I'm unsure how on to implement the methods.

When my viewController loads: [facebook requestWithGraphPath:@"me/friends" andDelegate:self];

This sends off the request and I implement the FBRequestDelegate method to receive it:

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

Works perfectly so far, I get an object with all the friend names and IDs. However, now I'd like to loop through each ID, and send off another few hundred requests. I already know how to setup the loop and the request call, but I've already used the didLoad method in this viewController, and I obviously need to handle the data differently once the data object gets returned.

Something to do with a (FBRequest *)? What is that, maybe I can go something like if(request == something)? Thanks

解决方案

You can retrieve the birthdays of your (or the user's) facebook friends with a single fql request.

You can read about fql here: http://developers.facebook.com/docs/reference/fql/

But here's some code for reference (this code is in a class defined to be a FBSessionDelegate, and 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"]];
}

这篇关于使用Facebook iOS SDK检索生日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆