1

I need to get a unique identifier linked to the user rather than the device, and since I don't want to force the user to register in my application, I'd like to get the email adress from his google acount.

I saw it was possible in this question : How to get the android devices primary email adress

But I can't manage to find anything related to Titanium on this subject. Does anyone know if there is a way to do so?

Community
  • 1
  • 1
Maniz
  • 415
  • 2
  • 7
  • 17
  • Have you checked http://developer.appcelerator.com/question/136935/login-with-google-oauth-20 and http://developer.appcelerator.com/question/157088/google-login, is this you were searching? – Anand Jul 11 '14 at 09:15
  • This seems to look like what I want..I'm gonna try that, thanks for your answer, maybe you can add it as an answer? – Maniz Jul 11 '14 at 09:21

2 Answers2

1

Try Login with Google (Oauth 2.0), commonJS module which will allow you to authenticate user with Google OAuth 2.0 and then work with Google APIs. Download the zip file and extract it. It also contains an example project. To test the example project, make sure you have a CLIENT_ID or CLIENT_SECRET.

Hope it helped you!

Anand
  • 5,323
  • 5
  • 44
  • 58
  • Actually, I'm not looking for a way to log in with a Google Acoount, just to retrieve the email adress, I'll look at your module to see if I can find what I want inside when I have some time, thanks again – Maniz Jul 11 '14 at 09:40
  • Well, I get back to this, and it seems that there is nothing in there allowing to retrieve the mail from Google account – Maniz Jul 16 '14 at 07:18
0

Well, I get back on that problem and found a solution, here is the way to get the Email adresse from Android in Titanium. The solution is to use Android classes directly through a Titanium module.

First, you have to create a Titanium module:

File > New > Mobile Module Project

For more informations about how to set up modules, refer to :

Wiki Appcelerator

Docs Appcelerator

Once your module is set, the method needed to retrieve the adress is :

@Kroll.method
public String getAccountMail()
{
    TiApplication appContext = TiApplication.getInstance();

    AccountManager manager = (AccountManager) appContext.getSystemService(Context.ACCOUNT_SERVICE);
    Account[] list = manager.getAccounts();

    return list.length > 0 ? list[0].name : null; 
}

Personally, I take the first one, but you can do whatever you want with that list. I found the sample for that in this answer : https://stackoverflow.com/a/7372239/1471580

Then, do not forget to add permission to your app:

<android xmlns:android="http://schemas.android.com/apk/res/android">
    <manifest>
        <uses-permission android:name="android.permission.GET_ACCOUNTS"/>
    </manifest>
</android>

You need to publish the module to use it, you can find how in my first links.

Finally, you can use it like that:

var module = require("namespace"); // exemple: "com.enterprise.project"
var mail = module.getAccountMail();

Hope it can help! Don't hesite to say it if something is unclear.

Community
  • 1
  • 1
Maniz
  • 415
  • 2
  • 7
  • 17