Enable Gmail username in app

These are the minimum data that I need to enter my application:

guid (Global Unique Identifier)

file name

Lname

Email

floor

to enter Facebook it was clear and could do this:

JSONObject json = Util.parseJson(facebook.request("me"); 

to get all the data above.

Is there a way to do something similar and just with Gmail?

I read this which says:

No, there is no such SDK (for example, facebook), and if you want to access Gmail email, then you need to implement your own email client and for this follow the link above shared by Spk.

But I want only a few details of the user, I do not need anything related to his mail, etc., that fall under authorization (if I'm right). I only need authentication:

I also read this one , but it doesn't seem like it will help anyone.

This is the code I have:

 import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks; import com.google.android.gms.common.GooglePlayServicesClient.OnConnectionFailedListener; import com.google.android.gms.plus.GooglePlusUtil; import com.google.android.gms.plus.PlusClient; import android.os.Bundle; import android.app.Activity; import android.app.ProgressDialog; import android.content.Intent; import android.content.IntentSender.SendIntentException; import android.util.Log; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity implements ConnectionCallbacks, OnConnectionFailedListener { private static final int REQUEST_CODE_RESOLVE_ERR = 7; private ProgressDialog mConnectionProgressDialog; private PlusClient mPlusClient; private ConnectionResult mConnectionResult; private String TAG = "GmailLogin"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); int errorCode = GooglePlusUtil.checkGooglePlusApp(this); if (errorCode != GooglePlusUtil.SUCCESS) { GooglePlusUtil.getErrorDialog(errorCode, this, 0).show(); } else { mPlusClient = new PlusClient.Builder(this, this, this) .setVisibleActivities( "http://schemas.google.com/AddActivity", "http://schemas.google.com/BuyActivity").build(); mConnectionProgressDialog = new ProgressDialog(this); mConnectionProgressDialog.setMessage("Signing in..."); Button signInButton = (Button) findViewById(R.id.sign_in_button); signInButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mConnectionResult == null) { mConnectionProgressDialog.show(); } else { try { mConnectionResult .startResolutionForResult( MainActivity.this, REQUEST_CODE_RESOLVE_ERR); } catch (SendIntentException e) { // Try connecting again. mConnectionResult = null; mPlusClient.connect(); } } } }); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public void onConnectionFailed(ConnectionResult result) { if (result.hasResolution()) { try { result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR); } catch (SendIntentException e) { mPlusClient.connect(); } } // Save the result and resolve the connection failure upon a user click. mConnectionResult = result; } @Override protected void onActivityResult(int requestCode, int responseCode, Intent intent) { if (requestCode == REQUEST_CODE_RESOLVE_ERR && responseCode == RESULT_OK) { mConnectionResult = null; mPlusClient.connect(); } } @Override public void onConnected() { String accountName = mPlusClient.getAccountName(); Toast.makeText(this, accountName + " is connected.", Toast.LENGTH_LONG) .show(); } @Override public void onDisconnected() { Log.d(TAG, "disconnected"); } @Override protected void onStart() { super.onStart(); mPlusClient.connect(); } @Override protected void onStop() { super.onStop(); mPlusClient.disconnect(); } } 

Any help is much appreciated, thanks.

0
source share
2 answers

You should not use Gmail to authenticate users with Google Accounts. Instead, you can use Google + to sign in to Android. This will allow you to access the user profile information after obtaining the necessary permissions using OAuth. Check out the manual here:

https://developers.google.com/+/mobile/android/sign-in

+3
source

These attributes will be transferred as claims in the original authentication, as well as with each subsequent authentication.

Google allows you to request that they include the country, email address, first name, language and last name as claims for an authentication token,

Since they do not provide uuid, you will need to create one email address. There is no support (which I could find) for getting sex.

+1
source

Source: https://habr.com/ru/post/1493367/


All Articles