logo
Tags down

shadow

Call a method in AccessToken.getCurrentAccessToken() when creating a login in Facebook with React Native


By : xufei zhao
Date : October 15 2020, 08:10 PM
this will help In my app I'm creating a login in Facebook with React Native, and this my code: , Insert this code:
code :
const _this = this;
async handleFacebookLogin() {
  this.loginWithFaceBook(resultChild.token);
_this.loginWithFaceBook(resultChild.token);
 async handleFacebookLogin() {
    const _this = this;
    LoginManager.logInWithReadPermissions(['public_profile', 'email']).then(
        function (result) {
            if (result.isCancelled) {
                console.log('Login cancelled')
            } else {
                console.log('Login success with permissions: ' + result.grantedPermissions.toString())
                let tokenFace = '';
                AccessToken.getCurrentAccessToken().then(
                    async (data) => {
                        data.accessToken)
                        let resultChild = await loginWithFaceBook(data.accessToken.toString(), "POST");
                        if (resultChild.username.length > 0) {
                            _this.loginFaceBook(resultChild.token);
                        }
                    });
            }
        },
        function (error) {
            console.log('Login fail with error: ' + error)
        }
    )
}


Share : facebook icon twitter icon

Facebook SDK(4.x): AccessToken.getCurrentAccessToken() returns null during run and not null in debug mode


By : user3827684
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Instead of trying to retrieve the profile again, after I successfully login to facebook I save all the info I want, including the FB Id, to a SQLite DB. No issues anymore.
Old:
code :
@Override
protected void onCreate(Bundle savedInstanceState) {
    //Remove title bar
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

    //set the view to the saved data and change the layout
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);

    FacebookSdk.sdkInitialize(getApplicationContext());
    // Initialize the SDK before executing any other operations,
    // especially, if you're using Facebook UI elements.



    /*~~~~~~    Google API Setup                           */
    mGoogleApiClient = new GoogleApiClient.Builder(Splash.this)
            .addConnectionCallbacks(Splash.this)
            .addOnConnectionFailedListener(Splash.this)
            .addApi(Plus.API)
            .addScope(Plus.SCOPE_PLUS_PROFILE)
            .build();

    /*~~~~~~~~~~~~~~    Facebook SDK setup and login event handler            */






    callbackManager = CallbackManager.Factory.create();








    //needs to be set in on activity result
    LoginManager.getInstance().registerCallback(callbackManager,
            new FacebookCallback<LoginResult>() {
                @Override
                public void onSuccess(LoginResult loginResult) {

                    Intent intent = new Intent(Splash.this, nearbyPlacesHolder.class);
                    startActivity(intent);
                }

                @Override
                public void onCancel() {
                    // App code
                    Log.d("FBLOGIN", "Cancel");
                    Toast.makeText(Splash.this, "Facebook Login Canceled", Toast.LENGTH_SHORT).show();
                }

                @Override
                public void onError(FacebookException exception) {
                    // App code
                    Log.d("FBLOGIN", "Error");

                }
            });






    //initializes the Facebook SeekBar Event Handlers
    //May be adding noises in here at a later date
    final SeekBar fb_seekbar = (SeekBar)findViewById(R.id.seekbar_fb);
    fb_seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            fb_progress = progress;


        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            if (fb_progress <= 75) {
                fb_seekbar.setProgress(4);
            } else {
                fb_seekbar.setProgress(100);
                //This is where the facebook sign in will be performed
                LoginManager.getInstance().logInWithReadPermissions(Splash.this, Arrays.asList("public_profile", "user_friends"));


                //Start the Intent for the next Activity
                //In the final code this intent will be the 3 tabbed activity (Faves, Nearby, Specials)
                //For now its just navigating to nearby
                //Intent intent = new Intent(Splash.this, nearbyPlacesHolder.class);
                //startActivity(intent);
            }
        }
    });

    //initializes the Google Plus SeekBar Event Handlers
    //May be adding noises in here at a later date
    final SeekBar google_slider = (SeekBar)findViewById(R.id.seekbar_google);
    google_slider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            google_progress = progress;

        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            if (google_progress <= 75) {
                google_slider.setProgress(0);
            } else {
                google_slider.setProgress(100);

                mGoogleApiClient.connect();

            }
        }
    });

    //initializes the Sign Up SeekBar Event Handlers
    //May be adding noises in here at a later date
    final SeekBar sign_up_seekbar = (SeekBar)findViewById(R.id.seekbar_regular);
    sign_up_seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            sign_up_progress = progress;

        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            if (sign_up_progress <= 75) {
                sign_up_seekbar.setProgress(4);
            } else {
                sign_up_seekbar.setProgress(100);
                //This is where the facebook sign in will be performed



                //Start the Intent for the next Activity
                //In the final code this intent will be the 3 tabbed activity (Faves, Nearby, Specials)
                //For now its just navigating to nearby
                //Intent intent = new Intent(Splash.this, makeProfile.class);
                //startActivity(intent);
            }
        }
    });


    if(isLoggedIn()){
        //Start the Intent for the next Activity
        //In the final code this intent will be the 3 tabbed activity (Faves, Nearby, Specials)
        //For now its just navigating to nearby
        Intent intent = new Intent(Splash.this, nearbyPlacesHolder.class);
        startActivity(intent);
        finish();
    }



}

public boolean isLoggedIn(){
    AccessToken accessToken = AccessToken.getCurrentAccessToken();
    Profile profile = Profile.getCurrentProfile();
    //Attempts to recognize if the user has logged in before
    if(accessToken !=null && profile !=null) {
            return true;
        }
        else{
            return false;
        }
}

React Native Facebook User Parse Authentication via magus/react-native-facebook-login


By : Raquel Silva
Date : March 29 2020, 07:55 AM
should help you out Looks like you've missed some functions being set on your button components directly, e.g.:
code :
onPress={this.onFbSignupPress}
...
onPress={this.onAlreadyAcctPress}
onPress={() => this.onFbSignupPress()}

onPress={this.onFbSignupPress.bind(this)}

Android facebook sdk AccessToken.getCurrentAccessToken() returns null


By : Ranith De Silva
Date : March 29 2020, 07:55 AM
wish helps you I Found the problem. FacebookSdk.sdkInitialize method was not in Application.onCreate method. I thought I had But it was at different place. So ALWAYS call FacebookSdk.sdkInitialize method from onCreate method at the top after calling super.onCreate

AccessToken.getCurrentAccessToken() is null


By : John Thornton
Date : March 29 2020, 07:55 AM
To fix the issue you can do Were you able to solve this? I have noticed that GraphRequest.newMeRequest sometimes does not delete old session data, so will return a null response in onComplete. As an alternative, you could use GraphRequest.newGraphPathRequest(accessToken, "/me"...), with very similar results.

AccessToken.getCurrentAccessToken() always returns null in Kotlin


By : tuyen do
Date : March 29 2020, 07:55 AM
around this issue The access token that was returned by the LoginManager will be saved in shared preferences, so the next time the app is opened, AccessToken.getCurrentAccessToken() should have the same access token. You can check out the samples provided with the SDK to see them work.
Related Posts Related Posts :
  • How to handle state on array of checkboxes?
  • React Native - Redux ~ Props updating when not getting called
  • Fast way to add elements into an Uint8ClampedArray typed array
  • How to retrieve values from a checkbox group generated dinamically with jquery when page loads
  • Progress bar between two dates (fetch "var" from script), HTML
  • Why do Every time I start my function I get NaN
  • Angular routing change in url
  • Javascript - Change symbol on embedded tradingview script.text
  • How to select specific option?
  • Checking booleans from multiple arrays simultaneously, without multiple if statements
  • How to get a subarray?
  • Javascript JSON woes
  • Use Jquery animate to have a button move a box to the next corner
  • Why is this JavaScript not interpreted as a code block when semi-colon is used?
  • Reload another page when I click on button
  • Should functions that call a callback function be bound?
  • For loop print in single line separated by spaces - JS
  • Add Javascript Variable into asp-route-data
  • Two different POST requests are making use of the same variable
  • Convert JSOn object into a flat JSON Array
  • Manually adding to an HTML range input gives unexpected results
  • Refreshing component after making api call Reactjs
  • Google App Script : Finding The Last Blank Row
  • I cant for the life of me figure out whats wrong with this script
  • Order divs by ID in Javascript
  • set new element class property value
  • How to pass a java variable to a different jsp page containing javascript?
  • Locked it method in chai
  • React JS : history.push is not a function error and it isn't navigating to a different page onclick of swal
  • How can i set timeout for localstorage for Angular 2+?
  • Must use destructuring props assignment
  • Jest Compared values have no visual difference. when testing arrays
  • Uncaught Error: #90211 ExtensionName Error - Node.JS, Heroku, JavaScript App using FusionCharts
  • Is it possible in firebase auth to update user and custom claims at the same time node?
  • Filter out capitalized letters
  • Yet Another Google Firebase Error "Function returned undefined, expected Promise or value"
  • How do I address method in a Vue.js component from inside callback function?
  • What is the name of this feature in JavaScript?
  • Vue js using scope-slot and trying to use a property from within but having no visibility
  • Dynamic javascript table won't display iterations from array
  • How to start/end smoke.js animation by clicking a nav button?
  • Map array of strings as object properties
  • Appending new inputs with JS wipes previous ones
  • Chai Request With URL instead of JS File
  • React Jest Async Tests
  • Unordered list bullet not showing at an expected location
  • How to create an array from an object?
  • How to get prefix name from html tag
  • javascript - Simulate a click event (tap with finger) on a button in iOS
  • How to get the value of checkboxes in a kendo grid
  • Uncaught TypeError: Object(...) is not a function at eval (global-styles.js)
  • Generate divs on scroll bottom
  • App deployed to Cloud Foundry fails to start
  • Show label and percentage in Google pie chart
  • Warn user before leaving web page if changes haven't been saved
  • Objects are not valid as a React child getting error when adding div?
  • why is callback not working in nodejs with mysql?
  • D3 v4 date ticks never display last item
  • How to assign a variable which function takes as a parameter
  • Javascript how hidden div onclick of phrase
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org