How to get Google User ID using the GMail address in Android?

余生颓废 提交于 2020-04-30 07:47:09

问题


How to get Google User ID something which looks like "1242343543557656",using the GMail address in Android?
I have searched for this and found answers only on, how to get gmail address and the user name.
What I want is the unique id provided by google to a gmail address?

These are some of the links that I have already referred.
-Accessing Google Account Id /username via Android
-How can I get the google username on Android?
-Get the Google ID used to download the application
-How to get the Android device's primary e-mail address


回答1:


Update as of 2016/12: The Google Identity toolkit has been superseded by Firebase Authentication.

I'm just adding to this question as I see it's gotten a lot of views. The user is required to be authenticated before their Google User ID can be obtained (otherwise you could pull credentials from any arbitrary email address). The recommended way to handle this on Android is to use the Google Identity toolkit:

Use Identity Toolkit in your Android App:
https://developers.google.com/identity/toolkit/android/

Quick-start app for Android:
https://developers.google.com/identity/toolkit/android/quickstart




回答2:


To the best of my knowledge, you can't get the google user id directly from Android. The only solution is to make an authenticated call to GAE, (i.e. a call with the 'User' parameter) and then read the id from the User object, and then return it to the Android client.

I think the easiest way for you to implement that (since you are using GAE) is to use google endpoints, which quite simplifies the authentication. The instructions and code for doing that authentication are here.

Then call getUserId() on the User object (the first param of your endpoint) and return it to the caller.



来源:https://stackoverflow.com/questions/19994610/how-to-get-google-user-id-using-the-gmail-address-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!