将用户的朋友数据导入Facebook的iOS应用程序

时间:2014-08-15 14:49:45

标签: ios facebook facebook-graph-api

我偶然发现了这个post,表示从facebook V2.0 API开始,我们无法从用户那里获取朋友数据。

我理解游戏邀请等等。但我想知道是否有任何方法可以将数据导入到应用程序的本地数据库中。我们的应用程序有点像每个朋友的日记,所以我们基本上需要为用户提供数据输入框架。

此功能是应用程序的核心功能,如果没有获取其朋友列表的本地,可行副本,确实很难。那里有解决方法吗?

鉴于我们的应用程序是如此" facebook朋友"定向,是否有可能在ios范围之外或其他任何方面实现更多?我知道我可能正抓着稻草,但我想我会提出建议。

是否有人知道链接是否有类似的限制?

有人知道是否可以根据用户的要求获取一位朋友的信息?

1 个答案:

答案 0 :(得分:0)

这是您获取所有用户朋友信息的方式(即使是那些不使用该应用的用户)

//Configure the request
NSString *fbToken = [FBSession activeSession].accessTokenData.accessToken;
NSString *fbURL = @"https://graph.facebook.com/me/friends?access_token=%@";
NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",fbURL, fbToken]];
NSURLRequest *friendRequest = [NSURLRequest requestWithURL:URL];
//Send the request
[NSURLConnection sendAsynchronousRequest:friendRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {

if (!connectionError) {

    NSDictionary *friendData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];

    NSLog(@"friend data = %@",friendData);

    //Grab friends ID (or whatever else you want, just replace dic[@"id"]] with dic[@"name"]] or something

    NSMutableArray *friendIDArray = [NSMutableArray array];

        for (NSDictionary *dic in friendData[@"data"]) {

            [friendIDArray addObject:dic[@"id"]];
        }

    }

}