Sitata / titanium_google_plus

Appcelerator Titanium module to wrap the google plus sdk.
MIT License
12 stars 9 forks source link

Uncaught error #3

Open manumaticx opened 10 years ago

manumaticx commented 10 years ago

I can't get it working on android. The signin method seems to either do nothing or throw an error like this:

12-02 13:35:54.236: W/System.err(19605): java.lang.NullPointerException: storage == null
12-02 13:35:54.243: W/System.err(19605):    at java.util.Arrays$ArrayList.<init>(Arrays.java:38)
12-02 13:35:54.243: W/System.err(19605):    at java.util.Arrays.asList(Arrays.java:155)
12-02 13:35:54.243: W/System.err(19605):    at com.sitata.googleplus.TitaniumGooglePlusModule.buildClient(TitaniumGooglePlusModule.java:299)
12-02 13:35:54.243: W/System.err(19605):    at com.sitata.googleplus.TitaniumGooglePlusModule.signin(TitaniumGooglePlusModule.java:339)
12-02 13:35:54.243: W/System.err(19605):    at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
12-02 13:35:54.243: W/System.err(19605):    at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:62)
12-02 13:35:54.243: W/System.err(19605):    at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:908)
12-02 13:35:54.243: W/System.err(19605):    at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1131)
12-02 13:35:54.243: W/System.err(19605):    at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:347)
12-02 13:35:54.243: W/System.err(19605):    at android.os.Handler.dispatchMessage(Handler.java:98)
12-02 13:35:54.243: W/System.err(19605):    at android.os.Looper.loop(Looper.java:135)
12-02 13:35:54.243: W/System.err(19605):    at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)
12-02 13:35:54.259: E/TiExceptionHandler(19605): (main) [7429,7429] ----- Titanium Javascript Runtime Error -----
12-02 13:35:54.259: E/TiExceptionHandler(19605): (main) [0,7429] - In alloy/controllers/account/login.js:100,20
12-02 13:35:54.259: E/TiExceptionHandler(19605): (main) [0,7429] - Message: Uncaught Error: storage == null
12-02 13:35:54.259: E/TiExceptionHandler(19605): (main) [0,7429] - Source:             google.signin({
12-02 13:35:54.281: E/V8Exception(19605): Exception occurred at alloy/controllers/account/login.js:100: Uncaught Error: storage == null

Any idea what could be the issue?

astjohn commented 10 years ago

So here's the deal. I started with another module to handle oauth single sign in stuff over here which I just pushed up for you. Then we noticed that google is moving all their oauth stuff to the google plus API and so I took a shot at wrapping up that API for titanium. As weird as it sounds, I've had more luck so far with ios. Signing in works on that platform, but not yet for android.

If you'd like to have a single sign on experience using the google account manager on the phone, I suggest doing what we currently have setup in our codebase which uses both modules:

function doGoogleOauth() {

  if (Titanium.Platform.name === "android") {
    var GoogleAuthUtil = require("com.sitata.googleauthutil");
    GoogleAuthUtil.setScope("oauth2:profile email");
    GoogleAuthUtil.pickUserAccount(function(result) {
      if (result.token && result.email) {
        doServerPost({provider: 'google', code: result.token});
      } else {
        handleBadPost();
      }
    });
  } else if (Titanium.Platform.name === "iPhone OS") {
    var google = require('com.sitata.googleplus');
    google.setClientId(Alloy.CFG.googleClientIdIos);
    google.setScopes(["profile", "email"]);
    google.signin({
      success: function(event) {
        if (event.accessToken) {
          $.sitataPost.setVisible(true);
          doServerPost({provider: 'google', code: event.accessToken});
        } else {
          handleBadPost();
        }
      },
      error: function(event) {
        Ti.API.info("ERROR! " + JSON.stringify(event));
        handleBadPost();
      }
    });

  }
}
manumaticx commented 10 years ago

Wow, thank you! I'll have a look at this.

manumaticx commented 10 years ago

@astjohn Okay, I think I'd rather use this module. Hence, I'll investigate getting the sign-in working on Android.

manumaticx commented 10 years ago

I know that this project may meant to wrap the Plus API. But since I'm using it only for the Google+ SignIn (only on Android for now), i've modified your code to accomplish this in a more simple way. If you want to check this out, I've pushed it to a separate branch in my fork: https://github.com/manumaticx/titanium_google_plus/tree/android-login

I removed the whole token fetching task and use the login scope to access basic user information. It works very fine. I'm using a login event here instead of callbacks. Used like this:

var google = require('com.sitata.googleplus');

google.addEventListener('login', function(e){
  if (e.success) {
    Ti.API.info( e.data );
  } else {
    Ti.API.error( e.error );
  }
});

function login() {
  if ( !google.isLoggedIn() ) {
    google.signin();
  } else {
    google.signout();
  }
};

If the login is successful (user has to grant the permission to access his public profile to the application), I get like this:

{
    "familyName": "Lehner",
    "givenName": "Manuel",
    "currentLocation": null,
    "nickname": null,
    "id": "110581755272647115675",
    "image": "https://lh3.googleusercontent.com/-joKTMHAFMtw/AAAAAAAAAAI/AAAAAAAAArs/cuWyvXih13A/photo.jpg?sz=50",
    "url": "https://plus.google.com/+ManuelLehner",
    "name": null,
    "email": "manumaticx@gmail.com",
    "gender": 0,
    "about": null,
    "isPlusUser": true,
    "birthday": null
}
astjohn commented 9 years ago

The issue I see with this, and partly why this sign in stuff needs lots of love is that there are a number of use cases and different tokens at work. For example, what if the user wants to fetch a one-time use token which is sent to the server such that the server can have offline access...

deckameron commented 9 years ago

I am using version 1.5.0 but I am also experiencing this error.

[WARN] : W/System.err: java.lang.NullPointerException: storage == null [WARN] : W/System.err: at java.util.Arrays$ArrayList.(Arrays.java:38) [WARN] : W/System.err: at java.util.Arrays.asList(Arrays.java:155) [WARN] : W/System.err: at com.sitata.googleplus.TitaniumGooglePlusModule.buildClient(TitaniumGooglePlusModule.java:296) [WARN] : W/System.err: at com.sitata.googleplus.TitaniumGooglePlusModule.signin(TitaniumGooglePlusModule.java:344) [WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method) [WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:62) [WARN] : W/System.err: at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:908) [WARN] : W/System.err: at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1131) [WARN] : W/System.err: at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:347) [WARN] : W/System.err: at android.os.Handler.dispatchMessage(Handler.java:98) [WARN] : W/System.err: at android.os.Looper.loop(Looper.java:135) [WARN] : W/System.err: at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112) [ERROR] : TiExceptionHandler: (main) [4471,4471] ----- Titanium Javascript Runtime Error ----- [ERROR] : TiExceptionHandler: (main) [0,4471] - In ui/handheld/android/LoginTabGroup/Login.js:105,11 [ERROR] : TiExceptionHandler: (main) [0,4471] - Message: Uncaught Error: storage == null [ERROR] : TiExceptionHandler: (main) [0,4471] - Source: google.signin({ [ERROR] : V8Exception: Exception occurred at ui/handheld/android/LoginTabGroup/Login.js:105: Uncaught Error: storage == null

astjohn commented 9 years ago

@deckameron, Can you try building master and let me know what happens?

deckameron commented 9 years ago

@astjohn By building master, you mean compile the module on my machine?

astjohn commented 9 years ago

@deckameron - yes, but if that's not possible, don't worry about it. I can eventually do it with a version bump and release, but it will take a while.

astjohn commented 9 years ago

@dyan02, I believe this is an issue regarding the sign in process. Currently, the sign in will perform 2 separate actions under the sign in process. The first thing it does is pull the user's google account credentials and signs in to Google Plus. The second step is that it takes these credentials and then uses AccountManager to create a token for offline use. The token in this case, can then be sent to a server for further processing. I think it will be best to separate these concerns in a future release.

mbilwar commented 8 years ago

Hello,

i am new to titanium and i want to Install Mobile Module in my project from this link: https://github.com/manumaticx/titanium_google_plus/tree/android-login in which @manumaticx has made some changes.

How to include this module into my project in titanium using Install Mobile Module?

Thank you in advance :)