【发布时间】:2012-09-27 23:26:54
【问题描述】:
我有一个启用了 Facebook user_photos 权限的应用。问题是如果我去 Facebook 并删除应用程序,iOS 不会注意到这一点。 ACAccountStore 表示我有权限,所以 requestAccess... 返回“已授予”,但当我尝试 SLRequest 时,我会收到类似 Error validating access token: User XXXXX has not authorized application YYYYY 的错误,并且该应用不会重新出现在 Facebook 中。
解决方法是转到设备上的“设置”->“Facebook”,然后关闭并重新打开我的应用程序的权限。下次我尝试requestAccess 时,系统会要求我再次确认访问权限,然后在 Facebook 中重新安装该应用程序,一切正常。
ACAccountStore *accountStore = [[[ACAccountStore alloc] init] autorelease];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[accountStore requestAccessToAccountsWithType:accountType
options:@{ACFacebookAppIdKey: kFacebookAppID,
ACFacebookPermissionsKey: @[@"user_photos"]}
completion:^(BOOL granted, NSError *error)
{
if( error ) {
NSLog( @"account permission error %@", error );
}
else if( granted ) {
NSURL *requestURL = [NSURL URLWithString:@"https://graph.facebook.com/me/albums"];
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:requestURL
parameters:[NSMutableDictionary dictionary]];
NSArray *accounts = [accountStore accountsWithAccountType:accountType];
if( [accounts count] > 0 ) {
request.account = accounts[0];
[request performRequestWithHandler:^ (NSData *responseData, NSHTTPURLResponse *response, NSError *error)
{
if( error ) {
NSLog( @"error accessing Facebook account: %@", error );
}
else {
NSDictionary *data = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:nil];
if( data[@"error"] != nil ) {
NSLog( @"error loading request: %@", data[@"error"] );
}
else {
NSLog( @"success! %@", data );
}
}
}];
}
else {
NSLog( @"error: no Facebook accounts" );
}
}
}];
就我而言,从 Facebook 删除应用程序后,我总是收到最终错误(“错误加载请求:”),没有其他错误。在设备的设置中切换应用程序的权限后,我就成功了。
【问题讨论】:
-
刚刚向 Apple 提交了一个错误...