【发布时间】:2013-04-30 02:54:47
【问题描述】:
令人困惑的难题:当我使用一个 URL 获取我的朋友列表时,我可以使用相同的 URL 但使用查询字符串 (?fields=id,name,picture) 和完全相同的权限来恢复列表指示“必须使用活动访问令牌来查询有关当前用户的信息”的错误。什么给了?
当前有效的权限是 publish_stream、email 和 read_stream。为什么添加该查询字符串会搞砸呢?我唯一能想到的是,我拥有的访问密钥不是我想的那样。有没有办法取出实际的访问密钥,在 NSLog 中公开,然后在图形资源管理器上进行测试?
有效的网址是:
https://graph.facebook.com/me/friends
不是的网址是:
https://graph.facebook.com/me/friends?fields=id,name,picture
这是实际获得权限的代码。事实上,这与 Stuart Breckenridge 在 GitHub 上免费提供的代码相同(谢谢老兄!)只要我不将 '?fields=name,id,picture' 附加到 api 调用的末尾,它似乎就可以正常工作:
-(void)requestPermissions
{
if (debugF) NSLog(@"FAM: requestPermissions");
// Specify the Facebook App ID.
_facebookAppID = @"123456789123456"; // You Must Specify Your App ID Here.
// Submit the first "read" request.
// Note the format of the facebookOptions dictionary. You are required to pass these three keys: ACFacebookAppIdKey, ACFacebookAudienceKey, and ACFacebookPermissionsKey
// Specify the read permission
_facebookPermissions = @[@"email"];
// Create & populate the dictionary the dictionary
_facebookOptions = @{ ACFacebookAppIdKey : _facebookAppID,
ACFacebookAudienceKey : ACFacebookAudienceFriends,
ACFacebookPermissionsKey : _facebookPermissions};
_facebookAccountType = [_facebookAccountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[_facebookAccountStore requestAccessToAccountsWithType:_facebookAccountType options:_facebookOptions completion:^(BOOL granted, NSError *error)
{
// If read permission are granted, we then ask for write permissions
if (granted) {
_readPermissionsGranted = YES;
// We change the _facebookOptions dictionary to have a publish permission request
_facebookPermissions = @[@"publish_stream", @"read_stream", @"friends_photos"];
_facebookOptions = @{ ACFacebookAppIdKey : _facebookAppID,
ACFacebookAudienceKey : ACFacebookAudienceFriends,
ACFacebookPermissionsKey : _facebookPermissions};
[_facebookAccountStore requestAccessToAccountsWithType:_facebookAccountType options:_facebookOptions completion:^(BOOL granted2, NSError *error)
{
if (granted2)
{
_publishPermissionsGranted = YES;
// Create the facebook account
_facebookAccount = [[ACAccount alloc] initWithAccountType:_facebookAccountType];
_arrayOfAccounts = [_facebookAccountStore accountsWithAccountType:_facebookAccountType];
_facebookAccount = [_arrayOfAccounts lastObject];
}
// If permissions are not granted to publish.
if (!granted2)
{
if (debugF) NSLog(@"Publish permission error: %@", [error localizedDescription]);
_publishPermissionsGranted = NO;
}
}];
}
// If permission are not granted to read.
if (!granted)
{
if (debugF) NSLog(@"Read permission error: %@", [error localizedDescription]);
_readPermissionsGranted = NO;
if ([[error localizedDescription] isEqualToString:@"The operation couldn’t be completed. (com.apple.accounts error 6.)"])
{
[self performSelectorOnMainThread:@selector(showError) withObject:error waitUntilDone:NO];
}
}
}];
}
【问题讨论】:
-
你能提供你正在使用的实际代码吗?
-
对于您上面列出的两个 URL,您需要一个用户访问令牌。基本权限应该足以获取您指定的字段。你在哪里得到错误?一般来说,当您使用 facebook SDK for iOS 时,一旦您打开会话并使用 SDK API 进行图形调用,它将自动使用用户的访问令牌。
-
umesh:我在上面添加了代码:)
-
阿米尔:感谢您的回复!但是,我只使用 iOS 社交框架,而不是用于 iOS 的 FB SDK。还是谢谢!
标签: ios facebook permissions