Search code examples
androidfacebookfacebook-graph-apiappcelerator

Appcelerator Android Facebook login error code 2500


Little Appcelerator Facebook login problem with Android API 6.2.0. The Facebook login screen shows. I login with no problem. It says that I've previously given permission to that app with Facebook. I click to "Continue". Then I get this error code 2500. Here's the log:

// I added the X's to the token & uid for this log

[DEBUG] :  TiFacebookModule: (main) [1,298128] authorize called, permissions length: 1
[DEBUG] :  TiFacebookModule: (main) [1,298129] authorizing permission: email
[DEBUG] :  ActivityWorkerProxy: (main) [27137,325266] ActivityWorkerProxy onActivityResult
[DEBUG] :  TiFacebookModule: (main) [251,325517] user is not null
[DEBUG] :  TiFacebookModule: (main) [0,325517] firing login event from module
[WARN] :   TiFacebookModule: (main) [0,325517] The getCanPresentOpenGraphActionDialog property is deprecated. This always returns true.
[DEBUG] :  TiFacebookModule: (main) [1,325518] get accessToken
[WARN] :   TiFacebookModule: (main) [0,325518] The getCanPresentShareDialog property is deprecated. This always returns true.
[INFO] :   Facebook: SUCCESS // {"type":"login","source":{"loggedIn":true,"canPresentOpenGraphActionDialog":true,"permissions":["email","public_profile"],"accessToken":"EAADVQzAhldwBAN3ZCLDyeVF6NiWoIxLV1x8KTeAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXifLwjJPSDE7BFckLwMxJPmTu3BecteHVyutEc2uxbTV4ccG6OciIIOsXpTpewNlZC5hJkV1l0NtsjrFZARKdZBABOcZASPHjs0XZA6o9JRqlwkAX2S40ZCG0AqzsZD","loginBehavior":null,"canPresentShareDialog":true,"expirationDate":"2018-01-10T21:22:24.457Z","uid":"1163XXXXXXX6528","apiName":"Ti.Module","bubbleParent":true,"invocationAPIs":[{"namespace":"Facebook","api":"createActivityWorker"},{"namespace":"Facebook","api":"createLikeButton"},{"namespace":"Facebook","api":"createLoginButton"}],"__propertiesDefined__":true,"_events":{"login":{}}},"data":"{\"id\":\"1163XXXXXXX6528\",\"name\":\"Byte Bbt\"}","uid":"1163XXXXXXX6528","cancelled":false,"bubbles":false,"success":true,"code":0,"cancelBubble":false}
[INFO] :   me?fields=name,email,first_name,last_name
[ERROR] :  TiFacebookModule: (main) [70,325588] requestWithGraphPath callback error: An active access token must be used to query information about the current user.
[INFO] :   results From Graph API: {"error":"An error code 2500 has occured. An active access token must be used to query information about the current user."}
[ERROR] :  TiExceptionHandler: (main) [2,325590] ----- Titanium Javascript Runtime Error -----
[ERROR] :  TiExceptionHandler: (main) [0,325590] - In undefined:1,1
[ERROR] :  TiExceptionHandler: (main) [0,325590] - Message: Uncaught SyntaxError: Unexpected token u in JSON at position 0
[ERROR] :  TiExceptionHandler: (main) [0,325590] - Source: undefined

This same code works perfectly on iOS:

var fb = require('facebook');
$.index.fbProxy = fb.createActivityWorker({lifecycleContainer: $.index});
fb.permissions = ['email']; 
fb.initialize();

fb.addEventListener('login', function(e) {
    if (e.success) {
        Ti.App.FBuid   = e.uid;
        Ti.App.FBtoken = e.source.accessToken;
        Ti.App.FBname  = JSON.parse(e.data).name;
        Ti.API.info('Facebook: SUCCESS // ' + JSON.stringify(e));

        // This test didn't work
        // "me?accessToken=" + Ti.App.FBtoken + "&uid=" + Ti.App.FBuid + "&u=" + Ti.App.FBuid + "&fields=name,email,first_name,last_name"

        Ti.API.info("me?fields=name,email,first_name,last_name");
        fb.requestWithGraphPath("me?fields=name,email,first_name,last_name", {}, 'GET', function(result) {
            Ti.API.info('results From Graph API: ' + JSON.stringify(result));
            var data = JSON.parse(result.result);
            Ti.API.info("-- email: " + data.email);
            Ti.App.FBemail = data.email;
            Ti.App.FBfname = data.first_name;
            Ti.App.FBlname = data.last_name;
        });
    } else if (e.cancelled) {
        Ti.API.info('Facebook: FAIL');
    } else {
        $.blackout.hide();
        Ti.API.info('Facebook: ERROR // ' + e.error);
        alert("Oops. Something went wrong.\nPlease try again.");
    }
});

fb.authorize();

Any idea how I can get rid of this "active access token" 2500 error? Thanks.


Solution

  • I guess you are using old format of passing fields to requestGraphApi.

    Try this, I have formatted your code a bit as following:

    var fb = require('facebook');
    
    // set permissions first
    fb.permissions = ['public_profile', 'email']; 
    
    // then add event listener
    fb.addEventListener('login', facebookLogin);
    
    // finally initialize
    fb.initialize();
    
    // attach proxy after initialisation
    $.index.fbProxy = fb.createActivityWorker({lifecycleContainer: $.index});
    
    
    // Pass fields as dictionary to be comaptible with latest graph api.
    function facebookLogin(e) {
        if (e.success) {
            Ti.App.FBuid   = e.uid;
    
            // I think you don't need accessToken to store, Facebook module will use it properly when you call graph api.
            Ti.App.FBtoken = e.source.accessToken;
            Ti.App.FBname  = JSON.parse(e.data).name;
    
            // pass fields as dictionary
            fb.requestWithGraphPath("me", {fields:'name,email,first_name,last_name,gender', 'GET', function(result) {
                Ti.API.info('results From Graph API: ' + JSON.stringify(result));
                var data = JSON.parse(result.result);
                Ti.API.info("-- email: " + data.email);
    
                // this is not recommended approach to modify internal api Ti.App
                Ti.App.FBemail = data.email;
                Ti.App.FBfname = data.first_name;
                Ti.App.FBlname = data.last_name;
            });
        } else if (e.cancelled) {
            Ti.API.info('Facebook: FAIL');
        } else {
            $.blackout.hide();
            Ti.API.info('Facebook: ERROR // ' + e.error);
            alert("Oops. Something went wrong.\nPlease try again.");
        }
    }
    
    
    fb.authorize();