通过新的iOS6社交框架查询Facebook用户数据 [英] Querying Facebook user data through new iOS6 social framework

查看:108
本文介绍了通过新的iOS6社交框架查询Facebook用户数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用iOS 6的新的Facebook集成API查询有关用户的信息。这是我使用的代码,这与在WWDC上演示的代码基本相同:

I am trying to query information about a user using iOS 6's new Facebook integration API. This is the code I'm using, which is basically identical to what they demoed at WWDC:

{
NSDictionary *parameters = @{};
NSURL *url = [NSURL URLWithString:@"https://graph.facebook.com/me"];
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                        requestMethod:SLRequestMethodGET
                                                  URL:url
                                           parameters:parameters];
request.account = self.account;
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
    NSLog(@"Facebook request received, status code %d", urlResponse.statusCode);
    NSString *response = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    NSLog(@"Response data: %@", response);
    dispatch_async(dispatch_get_main_queue(), ^{

    });
}];
}

问题是我从Facebook收到错误代码2500:活动访问令牌必须用于查询有关当前用户的信息。如果我将查询更改为https://graph.facebook.com/[facebook id],那么它的工作正常。我假设的问题是,当通过requestForServiceType发送请求时,iOS正在传递应用程序的访问令牌而不是用户的访问令牌。我只是不知道如何解决它。显然,预期和硬编码我的用户的Facebook ID不是一个选择。有什么建议么?

Problem is I am getting error code 2500 from Facebook: "An active access token must be used to query information about the current user." If I change the query to https://graph.facebook.com/[facebook id] then it works fine. I am assuming the problem is that iOS is passing the access token of the app instead of the user's access token when sending the request via requestForServiceType. I just don't know how to fix it. Obviously anticipating and hardcoding the Facebook IDs of my users is not an option. Any suggestions?

推荐答案

在paramete中添加您的活动访问令牌,如

add your active access token in paramete like

NSDictionary *parameters = [NSDictionary dictionaryWithObject:@"PUT_ACCESS_TOKEN_HERE" forKey:@"access_token"];

这篇关于通过新的iOS6社交框架查询Facebook用户数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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