我正在通过 Accounts Framework 集成 facebook,我搜索并获得了一些方法来做到这一点。它第一次工作,但后来它显示在日志下面并且没有提供任何信息。
日志:
Dictionary contains: {
error = {
code = 2500;
message = "An active access token must be used to query information about the current user.";
type = OAuthException;
};
}
我使用的代码
ACAccountStore *_accountStore=[[ACAccountStore alloc] init];;
ACAccountType *facebookAccountType = [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
// We will pass this dictionary in the next method. It should contain your Facebook App ID key,
// permissions and (optionally) the ACFacebookAudienceKey
NSArray * permissions = @[@"email"];
NSDictionary *options = @{ACFacebookAppIdKey :@"my app id",
ACFacebookPermissionsKey :permissions,
ACFacebookAudienceKey:ACFacebookAudienceFriends};
// Request access to the Facebook account.
// The user will see an alert view when you perform this method.
[_accountStore requestAccessToAccountsWithType:facebookAccountType
options:options
completion:^(BOOL granted, NSError *error) {
if (granted)
{
// At this point we can assume that we have access to the Facebook account
NSArray *accounts = [_accountStore accountsWithAccountType:facebookAccountType];
// Optionally save the account
[_accountStore saveAccount:[accounts lastObject] withCompletionHandler:nil];
//NSString *uid = [NSString stringWithFormat:@"%@", [[_accountStore valueForKey:@"properties"] valueForKey:@"uid"]] ;
NSURL *requestURL = [NSURL URLWithString:[@"https://graph.facebook.com" stringByAppendingPathComponent:@"me"]];
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:requestURL
parameters:nil];
request.account = [accounts lastObject];
[request performRequestWithHandler:^(NSData *data,
NSHTTPURLResponse *response,
NSError *error) {
if(!error){
NSDictionary *list =[NSJSONSerialization JSONObjectWithData:data
options:kNilOptions error:&error];
NSLog(@"Dictionary contains: %@", list );
userName=[list objectForKey:@"name"];
NSLog(@"username %@",userName);
userEmailID=[list objectForKey:@"email"];
NSLog(@"userEmailID %@",userEmailID);
userBirthday=[list objectForKey:@"birthday"];
NSLog(@"userBirthday %@",userBirthday);
userLocation=[[list objectForKey:@"location"] objectForKey:@"name"];
NSLog(@"userLocation %@",userLocation);
}
else{
//handle error gracefully
}
}];
}
else
{
NSLog(@"Failed to grant access\n%@", error);
}
}];
任何线索朋友出了什么问题...谢谢。