我有一个user_photos启用了Facebook 权限的应用.问题是,如果我去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" );
}
}
}];
Run Code Online (Sandbox Code Playgroud)
在我的情况下,我总是从Facebook删除应用程序后得到最后的错误("错误加载请求:"),没有其他错误.在设备的设置中切换应用程序的权限后,我获得了成功.
根据Apple的说法,这可以按预期工作(BS!).实际上,事实证明你必须先ACAccountStore通过电话与Facebook同步renewCredentialsForAccount.在这种情况下,结果是ACAccountCredentialRenewResultRejected.然后您可以ACAccountStore requestAccessToAccountsOfType再次呼叫,最终会提示用户再次允许您的应用.
| 归档时间: |
|
| 查看次数: |
2255 次 |
| 最近记录: |