Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7415113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:14:07+00:00 2026-05-29T07:14:07+00:00

Trying to figure out how to use the JavaScript SDK. I’m new to JavaScrip.

  • 0

Trying to figure out how to use the JavaScript SDK. I’m new to JavaScrip. I was able to use the PHP SDK but want to run my stuff clientside. Anyhoo, I don’t really understand the SDK documentation on the develop site. So the base code is:

<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
    FB.init({
            appId      : 'YOUR_APP_ID', // App ID
            channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
            status     : true, // check login status
            cookie     : true, // enable cookies to allow the server to access the session
            xfbml      : true  // parse XFBML
    });

    // Additional initialization code here
};

// Load the SDK Asynchronously
(function(d){
        var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
        js = d.createElement('script'); js.id = id; js.async = true;
        js.src = "//connect.facebook.net/en_US/all.js";
        d.getElementsByTagName('head')[0].appendChild(js);
}(document));

Which I think I understand…it loads the SDK and then runs the FB.init stuff once it loads. I don’t know where to put all of the OAuth stuff though, and how to structure the login request (i.e. if not logged in the make a button and if you are then return access token etc.

Can someone hold my hand through this beginning part. I’ve searched everywhere and I just don’t quite get it.

Edit:

Okay, second try with authentication. Didn’t work:

<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
    FB.init({
            appId      : 'XXX', // App ID
            channelUrl : 'XXX', // Channel File
            status     : true, // check login status
            cookie     : true, // enable cookies to allow the server to access the session
            xfbml      : true  // parse XFBML
    });

    // Additional initialization code here
    FB.getLoginStatus(function(response) {
            if (response.status === 'connected') {
                // the user is logged in and connected to your
                // app, and response.authResponse supplies
                // the user's ID, a valid access token, a signed
                // request, and the time the access token 
                // and signed request each expire
                var uid = response.authResponse.userID;

                var accessToken = response.authResponse.accessToken;
                FB.api('/me', function(response) {
                        alert(response.name);
                });

            } else if (response.status === 'not_authorized') {
                FB.login(function(response) {
                        if (response.authResponse) {
                            console.log('Welcome!  Fetching your information.... ');
                            FB.api('/me', function(response) {
                                    console.log('Good to see you, ' + response.name + '.');
                                    FB.logout(function(response) {
                                            console.log('Logged out.');
                                    });
                            });
                        } else {
                            console.log('User cancelled login or did not fully authorize.');
                        }
 }, {scope: 'email'});
            } else {

            }
    })

};

// Load the SDK Asynchronously
(function(d){
        var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
        js = d.createElement('script'); js.id = id; js.async = true;
        js.src = "//connect.facebook.net/en_US/all.js";
        d.getElementsByTagName('head')[0].appendChild(js);
}(document));

</script>

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:14:08+00:00Added an answer on May 29, 2026 at 7:14 am

    Just below this line,
    // Additional initialization code here
    is where the oauth stuff goes.

    I would suggest getting used to calling FB.getLoginStatus() first. See: http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/


    EDIT

    based upon the question edit above
    This should be done inside the window.fbAsyncInit function

    FB.api('/me', function(response) {
            alert(response.name);
    });
    

    and only after you’ve checked the getLoginStatus() so you know if the person is logged in or not.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out how to use Zend_Db_Table_Abstract correctly. I want to return
I'm new to Rails development, and I'm trying to figure out how to use
As title said, I'm trying to figure out how to use javascript and jquery
I`m a JavaScript/programming newbie trying to figure out the new bookmarklet that's been released
Trying to figure out a way to use Javascript to set up a little
i'm trying to figure out how much i can use of the javascript language
I am trying to use figure out how xpath is working in FireFox, but
Trying to figure out which to use.
I'm trying to figure out how to use Emacs Code Browser (ECB) and one
I'm trying to figure out how to use the java.util.logging features. All of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.