1

令人困惑的难题:当我使用一个 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];
             }
         }
     }];
}
4

1 回答 1

2

事实证明,我最初的问题的答案比我想象的要简单:

NSString *acessToken = [NSString stringWithFormat:@"%@", self.facebookAccount.credential.oauthToken];

然而,对所有为对话做出贡献的人表示敬意。

于 2013-05-09T05:19:15.713 回答