【发布时间】:2013-02-08 15:24:18
【问题描述】:
我正在尝试获取用户详细信息,但目前无法获取图像。这是我遇到的错误:
{
error = {
code = 2500;
message = "An active access token must be used to query information about the current user.";
type = OAuthException;
};
}
这是我的代码:
if(!self.store)
{
ACAccountStore *store1 = [[ACAccountStore alloc] init];
self.store=store1;
[store1 release];
}
ACAccountType *fbAccountType =
[store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSArray * permissions = @[@"read_stream", @"publish_stream",@"email", @"user_birthday",@"publish_actions",@"user_photos"];
NSDictionary * dict = @{ACFacebookAppIdKey : @"my_key", ACFacebookPermissionsKey : permissions, ACFacebookAudienceKey : ACFacebookAudienceOnlyMe};
// Request permission from the user to access the available Twitter accounts
[store requestAccessToAccountsWithType:fbAccountType options:dict completion:^(BOOL granted, NSError *error) {
__block NSString * statusText = nil;
if (granted) {
statusText = @"Logged in";
NSArray * accounts = [store accountsWithAccountType:fbAccountType];
store = [accounts lastObject];
account = [accounts objectAtIndex:0];
NSLog(@"account is: %@", account);
NSURL *requestURL = [NSURL URLWithString:@"https://graph.facebook.com/me?fields=picture"];
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:requestURL
parameters:nil];
request.account = account;
[request performRequestWithHandler:^(NSData *data,
NSHTTPURLResponse *response,
NSError *error) {
if(!error){
NSDictionary *list =[NSJSONSerialization JSONObjectWithData:data
options:kNilOptions error:&error];
NSLog(@"Dictionary contains: %@", list );
}
else{
//handle error gracefully
}
}];
}
如果我使用https://graph.facebook.com/me 作为网址,那么它可以正常工作。但我也需要个人资料照片。怎么办?
【问题讨论】:
-
因为错误表明您没有通过活动访问令牌。尝试工作
-
我应该在哪里传递该令牌?正如我所说,如果我查询 graph.facebook.com/me 而不是 graph.facebook.com/me?fields=picture 它工作正常
-
我的回答对你有帮助吗?
-
嗨 Mayank,你是怎么解决这个问题的?如果您解决了这个问题,请告诉我?