×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    7

    Create user ID in Facebook.js

    Code:
    Qt.include("databaseFile.js")
    
    
    
    
    var accessToken = "";
    var notificationsLoaded = false;
    var lastReadNotificationID = "";
    
    function setAccessToken(token) {
        accessToken = token;
        mainAccessToken = token;
        isLoggedIn = true;
        isGetAccessTokenCalled =false;
    }
    
    function getAccessToken(code) {
         isGetAccessTokenCalled = true;
    
    
        var url = "https://graph.facebook.com/oauth/access_token?client_id=<------ID----->&redirect_uri=https://www.facebook.com/connect/login_success.html&client_secret=<-----SECRET-------->&code=" +code;
        doWebRequest("GET", url, "", parseAccessToken);
    }
    
    function setEmptyKey(accessToken)
    {
      setKeyValue("accesstoken", accessToken);
    }
    
    
    function parseAccessToken(response) {
        accessToken = "access_token=" + parseParameter(response, "access_token");
        window.mainAccessToken = accessToken;
    
    
        setKeyValue("accesstoken", accessToken);
        isLoggedIn = true;
        isGetAccessTokenCalled = false;
    
        loadHomeFeed();
        loadFriends();
    }
    
    function loadHomeFeed() {
        var url = "https://graph.facebook.com/me/home?" + mainAccessToken;
    
        doWebRequest("GET", url, "", parseHomeFeed);
    }
    
    
    // adding friends profile
    function loadFriendsProfile(id)
    {
        myFriendsProfileModel.clear();
       var url = "https://graph.facebook.com/" + id + "?fields=name,id,location,picture&" + mainAccessToken;
        doWebRequest("GET", url, "", parseProfile);
    
    
    }
    
    function parseProfile(response) {
        var user = eval("[" + response + "]")[0];
    
         if(user.location!==undefined)
            {
    
                if(user.location.id !== "" || user.location.name !==  null )
                {
    
                       myFriendsProfile.userId = user.id;
                       myFriendsProfile.userName= user.name;
                       myFriendsProfile.userImage = user.picture;
                       myFriendsProfile.userLocationId = (user.location!==undefined ? user.location.id : "");
                       myFriendMapModel.locationName= myFriendsProfile.userLocationName = (user.location!==undefined ? user.location.name : "");
                    myFriendMapModel.refresh(); //load user location on map
    
    
    
                }
             else{
                    myFriendsProfile.userId = user.id;
                    myFriendsProfile.userName= user.name;
                    myFriendsProfile.userImage = user.picture;
                    myFriendsProfile.userLocationId ="";// (user.location!==undefined ? user.location.id : "");
                    myFriendsProfile.userLocationName ="";// (user.location!==undefined ? user.location.name : "");
    
    
    
                }
    
    
    
        }
            else{
                myFriendsProfile.userId = user.id;
                myFriendsProfile.userName= user.name;
                myFriendsProfile.userImage = user.picture;
                myFriendsProfile.userLocationId ="";// (user.location!==undefined ? user.location.id : "");
                myFriendsProfile.userLocationName = "";//(user.location!==undefined ? user.location.name : "");
    
    
    
               }
    
    
            closeWaitingIndicator(); //indi
    
    
    
    }
    function    getFriendsLocationInfo()
    {
    
        if(myFriendMapModel.count!==0)
        {
                feedModelUserLocation.userLatitude = myFriendsProfile.userCordinateLat =myFriendMapModel.get(0).lat;
                feedModelUserLocation.userLongitude = myFriendsProfile.userCordinateLon =myFriendMapModel.get(0).lng;
    
    
        }
    
    }
    
    
    
    
    //end of friends profile
    
    function loadUserWall(id) {
        meWallModel.clear();
        var url = "https://graph.facebook.com/" + id + "/feed?" + mainAccessToken;
        doWebRequest("GET", url, "", parseUserWallFeed);
    }
    
    function loadAlbums(id) {
        meAlbumsModel.clear();
        var url = "https://graph.facebook.com/" + id + "/albums?" + mainAccessToken;
        doWebRequest("GET", url, "", parseAlbums);
    }
    
    function parseAlbums(response) {
        var data = eval("[" + response + "]")[0].data;
        var count = 0;
        for(var i in data) {
            var album = data[i];
            var updated = parseDate(album.updated_time);
            var albumUpdated = prettyDate(updated);
            meAlbumsModel.append({
                               "cover": "https://graph.facebook.com/" + album.id + "/picture?type=thumbnail&" + 
    
    
    
     ...... ECC.... CODE BY KASVOPUS
    HOW DO I FIND MY USER ID CODE FROM THIS?

    I HAVE TO INTEGRATE THIS?
    Code:
    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;
      } else if (response.status === 'not_authorized') {
        // the user is logged in to Facebook, 
        //but not connected to the app
      } else {
        // the user isn't even logged in to Facebook.
      }
    });

  2. #2
    Registered User
    Join Date
    Jul 2012
    Posts
    7

    Re: Create user ID in Facebook.js

    help pls..

  3. #3
    Nokia Developer Expert
    Join Date
    Jun 2012
    Posts
    55

    Re: Create user ID in Facebook.js

    Perhaps you can try something like

    Code:
    var globalUserID = null;
    
    function loadUser() {
       var url = "https://graph.facebook.com/me?" + mainAccessToken;
       doWebRequest("GET", url, "", parseUser);
    }
    
    function parseUser(response) {
       var user = eval("[" + response + "]")[0];
       globalUserID = user.id;    
    }
    Br,
    Villep

  4. #4
    Registered User
    Join Date
    Jul 2012
    Posts
    7

    Re: Create user ID in Facebook.js

    in to file ".js"
    copy this
    function loadUser() {
    var url = "https://graph.facebook.com/me?" + mainAccessToken;
    doWebRequest("GET", url, "", parseUser);
    }

    function parseUser(response) {
    var user = eval("[" + response + "]")[0];
    globalUserID = user.id;
    }
    and in to file "main.qml" i have this
    WITH THIS I HAVE TO FIND THE PROFILE IMG'S CONNECTED

    Image {
    id: image8
    x: 0
    y: 0
    width: 123
    height: 114
    source: "https://graph.facebook.com/" + ID ------->Facebook.parseUser() + "/picture";
    visible: true
    fillMode: Image.PreserveAspectFit
    }
    but does not work, what is wrong?
    thanks

  5. #5
    Nokia Developer Expert
    Join Date
    Jun 2012
    Posts
    55

    Re: Create user ID in Facebook.js

    The version of parseUser doesn't return a value atleast. So if you are are trying to use the return value to get the userid then you should add
    Code:
    return user.id;
    to the end of parseUser.

    Br,
    Villep

  6. #6
    Registered User
    Join Date
    Jul 2012
    Posts
    7

    Re: Create user ID in Facebook.js

    TypeError: Result of expression 'user' [undefined] is not an object.
    in this line
    globalUserID = user.id;

  7. #7
    Nokia Developer Expert
    Join Date
    Jun 2012
    Posts
    55

    Re: Create user ID in Facebook.js

    You shouldn't call parseUser yourself, because it takes the HTTPResponse as parameter which should be given by your doWebRequest function. Instead call loadUser somewhere in your code. Then make sure you have declared
    Code:
    var globalUserID = ""
    on top of the JavaScript file. This way you can simply access the userID after loadUser function by Facebook.globalUserID

    For example your Image could have.
    Code:
    Image {
        source: "https://graph.facebook.com/" + Facebook.globalUserID + "/picture"
    }
    Br,
    Villep

  8. #8
    Registered User
    Join Date
    Jul 2012
    Posts
    7

    Re: Create user ID in Facebook.js

    Quote Originally Posted by Villep View Post
    You shouldn't call parseUser yourself, because it takes the HTTPResponse as parameter which should be given by your doWebRequest function. Instead call loadUser somewhere in your code. Then make sure you have declared
    Code:
    var globalUserID = ""
    on top of the JavaScript file. This way you can simply access the userID after loadUser function by Facebook.globalUserID

    For example your Image could have.
    Code:
    Image {
        source: "https://graph.facebook.com/" + Facebook.globalUserID + "/picture"
    }
    Br,
    Villep
    :S grrgrggr


    QML Image: Error downloading https://graph.facebook.com//picture - server replied: Internal Server Error

    I do not understand why it does not work: (
    thanks anyway

  9. #9
    Nokia Developer Expert
    Join Date
    Jun 2012
    Posts
    55

    Re: Create user ID in Facebook.js

    That happens when the userID is not set yet, before loadUser was called. One work around is the following.

    Code:
    Image {
        source: Facebook.globalUserID == "" ? "" : "https://graph.facebook.com/" + Facebook.globalUserID + "/picture"
    }
    Which makes the source empty so no image gets loaded until a valid userID gets set.

    Br,
    Villep

Similar Threads

  1. Replies: 6
    Last Post: 2008-10-01, 16:26
  2. HELP... USER 42..Create folder
    By liafail in forum Symbian
    Replies: 0
    Last Post: 2005-10-10, 08:53
  3. Hw to Create user authentication to my application
    By praveena in forum Mobile Java General
    Replies: 0
    Last Post: 2005-09-21, 06:08
  4. How to create a program without user interface
    By TrungThanhMtad in forum Symbian User Interface
    Replies: 1
    Last Post: 2005-03-07, 03:12

Posting Permissions

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