gpt4 book ai didi

facebook - ACAccountStore Facebook 错误

转载 作者:行者123 更新时间:2023-12-02 19:18:49 24 4
gpt4 key购买 nike

我有一个启用了 Facebook user_photos 权限的应用。问题是,如果我访问 Facebook 并删除该应用程序,iOS 不会注意到这一点。 ACAccountStore 说我有权限,因此 requestAccess... 返回“granted”,但是当我尝试 SLRequest 时,我收到错误例如验证访问 token 时出错:用户 XXXXX 尚未授权应用程序 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 的说法,这符合预期(BS!)。在实践中,事实证明,您必须首先通过调用 renewCredentialsForAccount 来使 ACAccountStore 与 Facebook 同步。在本例中,结果为 ACAccountCredentialRenewResultRejected。然后您可以再次调用 ACAccountStore requestAccessToAccountsOfType,最终将提示用户再次允许您的应用。

关于facebook - ACAccountStore Facebook 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12631526/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com