SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Use FB.api to store global javascript variable

    I want to store the user id from FB.api into a global variable that I can use in other functions... how do I do this? I have the following code but it doesnt work..

    Code:
    var fbuserId;
    
        function getFbid() {
    
    
            FB.api('/me', function(response) {
               fbuserId =  response.id;
            }); 
    
            return fbuserId;
        }
    
    params.fbuid = getFbid();   // calling the getFbid() to return the variable, but returns nothing

  2. #2
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I have no idea what "Fb.api" is; however.....

    1) have you tried placing alert messages in your functions to see if you are getting in, what values are being sent, received?
    2)
    FB.api('/me', function(response) {

    FB.api("\/me",.....
    Where the World Once Stood
    the blades of grass
    cut me still

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Vincent Puglia View Post
    Hi,

    I have no idea what "Fb.api" is; however.....

    1) have you tried placing alert messages in your functions to see if you are getting in, what values are being sent, received?
    2)
    FB.api('/me', function(response) {

    FB.api("\/me",.....
    FB.api is a method for Facebook Graph api.. but the problem I guess is more related to storing variables from within functions

    I have tried to do the alert inside the function and it outputs the correct data, but when I try to store the data in the global variable fbuserId for some reason it aint working

  4. #4
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    you can't do like that because FB.api is asyn
    so you never know when uid is available
    take a look
    http://stackoverflow.com/questions/7...lback-function
    Bye


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •