4

我可以通过以下方式访问用户的 Facebook:

[accStore requestAccessToAccountsWithType:fbAccountType
                                           options:options
                                        completion:^(BOOL granted, NSError *error) {
                                            if (granted) {
                                                // If access granted, then get the Facebook account info
                                                NSArray *accounts = [accStore
                                                                     accountsWithAccountType:fbAccountType];
                                                ACAccount *acc = [accounts lastObject];

                                                // Get the access token, could be used in other scenarios
                                                ACAccountCredential *fbCredential = [acc credential];
                                                NSString *accessToken = [fbCredential oauthToken];
                                                NSLog(@"Facebook Access Token: %@", accessToken);


                                                // Add code here to make an API request using the SLRequest class

                                            } else {
                                                NSLog(@"Access not granted");
                                            }
                                        }];

这打印出来:

 Facebook Access Token: (null)

我被授予访问权限,但令牌为空。我究竟做错了什么?

谢谢

4

2 回答 2

4

我已经通过更新凭据解决了这个问题。也就是说,在授予对 FB 的访问权限后,但在 ACAccountCredential 的oauthToken返回 nil 的情况下,我们只需调用 ACAccountStore 的renewCredentialsForAccount 即可。凭证被更新,然后令牌有效!

于 2015-02-19T17:39:15.453 回答
1

以下是来自 Apple 文档的一些信息:

@property(nonatomic, retain) ACAccountCredential *credential Discussion 此属性是必需的,必须在保存帐户之前设置。出于隐私原因,保存帐户后无法访问此属性。

在您的代码中, [acc credential] 将返回 null

供参考,http://developer.apple.com/library/ios/#documentation/Accounts/Reference/ACAccountClassRef/Reference/Reference.html#//apple_ref/doc/uid/TP40011019

在这里找到了一个类似的帖子:Get Facebook access token from Social.framework(iOS6)

希望这能有所帮助。

于 2013-07-19T04:27:01.210 回答