How to get access token from FB.login method in javascript SDK

Digital Marketing Facebook Marketing API 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating
_x000D_ _x000D_ I need to get the access token from FB.login method in Javascript SDK. My login code is FB.login(function(response) { if (response.session) { if (response.perms) { } else { // user is logged in, but did not grant any permissions alert("No Permission.."); } } else { // user is not logged in alert("Please login to facebook"); } }, {perms:'read_stream,publish_stream,offline_access'}); Is there any way to get access token? I am able to get the access token using PHP.

Posted on 16 Aug 2022, this text provides information on Facebook Marketing API related to Digital Marketing. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago
_x000D_ You can get access token using FB.getAuthResponse()['accessToken']: FB.login(function(response) { if (response.authResponse) { var access_token = FB.getAuthResponse()['accessToken']; console.log('Access Token = '+ access_token); FB.api('/me', function(response) { console.log('Good to see you, ' + response.name + '.'); }); } else { console.log('User cancelled login or did not fully authorize.'); } }, {scope: ''}); Edit: Updated to use Oauth 2.0, required since December 2011. Now uses FB.getAuthResponse(); If you are using a browser that does not have a console, (I'm talking to you, Internet Explorer) be sure to comment out the console.log lines or use a log-failsafe script such as: if (typeof(console) == "undefined") { console = {}; } if (typeof(console.log) == "undefined") { console.log = function() { return 0; } }

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.