Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-17614

Android: Facebook-Login-Callback needs JSON.parse (parity)

    Details

    • Type: Bug
    • Status: Open
    • Priority: None
    • Resolution: Unresolved
    • Affects Version/s: Release 3.3.0
    • Fix Version/s: None
    • Component/s: Android
    • Environment:

      Titanium SDK: 3.3.0.GA
      Titanium CLI: 3.3.0
      OS X Version: 10.9.3
      Android: 4.4.3
      iOS: 7.1.2

      Description

      Problem Description

      I recently discovered an issue on Android when logging into Facebook to use the user-data like name & id. Therefor the login callback returns a "data" object, which needs to be parsed manually on Android, but in iOS you don't need to do anything extra.

      Steps to reproduce

      • Create a simple project.
      • Update app.js with:

         
        var fb = require("facebook");
        var win = Ti.UI.createWindow({backgroundColor: "#fff"});
        var btn = Ti.UI.createButton({title: "Facebook-Login"});
         
        btn.addEventListener("click", doLogin);
        fb.addEventListener("login", debugLogin);
         
        function doLogin() {
            fb.appid = "***************";
            fb.permissions = ["publish_stream"];
            fb.forceDialogAuth = false;
            fb.authorize();
        }
         
        function debugLogin(e) {
            Ti.API.info(JSON.stringify(e.data));
            alert(e.data.name); // Doesn't work for android
            // var t =JSON.parse(e.data); // Does work for android.
            // alert(t.name); // Does work for android.
        }
         
        win.add(btn);
        win.open();
        

      • Add facebook module in tiapp.xml
      • Run on android device

      Extra info

      The difference in the callbacks are here.
      iOS: https://gist.github.com/hansknoechel/9e63d4b683bd72cc29bd
      Android: https://gist.github.com/hansknoechel/f0f3280fda26f98d52c0

      The bug was also discussed 2 years ago in the Q&A: https://developer.appcelerator.com/question/135341/titaniumfacebook-login-callback---cant-access-user-data-on-android-device

      Workaround

      The bug can be "fixed" by using a conditional statement like:

      var data = (OS_ANDROID) ? JSON.parse(e.data) : e.data;
      

      But a consistent behaviour is clearly the better way.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              hknoechel Hans Knöchel
            • Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-19150
                  Sync status:
                  ERROR
                  Last received:
                  Last sent:

                  Git Integration