React-native-fbsdk: How to get the access token?

Created on 16 Apr 2016  路  7Comments  路  Source: facebook/react-native-fbsdk

Hi, I was running RN 0.19 up until the other day, when I moved to 0.23. I had relied on the logInWithPermissions function from require('NativeModules').FBLoginManager; in order to get the accessToken for a user so I can authenticate in my app... but it seems that the new version doesn't support getting the access token. Instead, I get:

 { 
  declinedPermissions: [],  
  grantedPermissions: [ 'user_friends', 'email' ],
  isCancelled: false 
}

Any help would be much appreciated.

EDIT: I am running on Android.

Most helpful comment

import FBSDK, {
  LoginManager,
  AccessToken
} from 'react-native-fbsdk'

// Login... 
AccessToken.getCurrentAccessToken().then((accessToken) => console.log(accessToken))

All 7 comments

Having the same exact issue. Any luck?

Still nothing... will try to investigate more today. But nothing in the code has jumped out at me.

import FBSDK, {
  LoginManager,
  AccessToken
} from 'react-native-fbsdk'

// Login... 
AccessToken.getCurrentAccessToken().then((accessToken) => console.log(accessToken))

I'll give that a go tomorrow, thanks a lot!

Quite embarrassed that I didn't spot the FBAccessToken file... too many late nights :X

When I console.log(accessToken) it says object Object. When I console.log(accessToken.token) it logs undefined. Any suggestions on how to get the token as string?

Thanks in advance!

console.log(accessToken.accessToken)

Just want to add this in here for anyone using the LoginButton

You'd do something like this:

 <LoginButton
            publishPermissions={["publish_actions",]}
            onLoginFinished={
              (error, result) => {

                if (error) {
                  alert("login has error: " + result.error);
                } else if (result.isCancelled) {
                  alert("login is cancelled.");
                } else {
                   // This prints out the access token object (includes expiration time and etc...)   
                   AccessToken.getCurrentAccessToken().then((accessToken) => console.log(accessToken))
                }
              }
            }
            onLogoutFinished={() => alert("logout.")} />
Was this page helpful?
0 / 5 - 0 ratings

Related issues

emroot picture emroot  路  5Comments

pyeonjaesik picture pyeonjaesik  路  5Comments

andfs picture andfs  路  5Comments

akash-rajput picture akash-rajput  路  4Comments

pranny picture pranny  路  6Comments