ACAccountCredential对oauthToken返回null [英] ACAccountCredential returns null for oauthToken

查看:232
本文介绍了ACAccountCredential对oauthToken返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am getting access to user's facebook via:

[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)

令牌为null。我做错了什么?

I am granted access, but the token is null. What am I doing wrong?

感谢

推荐答案

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

I've solved the problem by renewing the credentials. That is, after access to FB has been granted, but in the case where ACAccountCredential's oauthToken returns nil, we just call ACAccountStore's renewCredentialsForAccount. Credentials are renewed, and after that the token is valid!

这篇关于ACAccountCredential对oauthToken返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆