ACAccountCredential returns null for oauthToken

I am accessing custom 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"); } }]; 

This produces:

  Facebook Access Token: (null) 

I have been granted access, but the token is zero. What am I doing wrong?

thanks

+4
source share
2 answers

I solved the problem by updating credentials. That is, after access to the FB was granted, but in the case where the ACAccountCredential oauthToken returns zero, we simply call ACAccountStore renewCredentialsForAccount . Credentials are updated, and after that the token is valid!

+4
source

Here is some info from Apple doc:

@property (non-atomic, save) ACAccountCredential * credentials Discussion This property is necessary and must be set before the account is saved. For privacy reasons, this property is not available after saving the account.

As in your code, [acc credential] will return null

For reference http://developer.apple.com/library/ios/#documentation/Accounts/Reference/ACAccountClassRef/Reference/Reference.html#//apple_ref/doc/uid/TP40011019

Found a similar entry here: Get Facebook access token from Social.framework (iOS6)

Hope this helps.

+1
source

Source: https://habr.com/ru/post/1492215/


All Articles