我有一个应用程序,启用了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删除应用程序后,我总是得到最后的错误("error none request:"),其他错误都没有。在设备的设置中切换应用程序的权限后,我获得了成功。
发布于 2013-02-02 08:15:49
根据苹果公司的说法,这是预期的工作(废话!)。实际上,你必须先调用renewCredentialsForAccount才能使ACAccountStore与Facebook同步。在本例中,结果为ACAccountCredentialRenewResultRejected。然后您可以再次调用ACAccountStore requestAccessToAccountsOfType,最终将提示用户再次允许您的应用程序。
https://stackoverflow.com/questions/12631526
复制相似问题