Using Android GoogleSignIn with GmailScopes.GMAIL_SEND (gmail api)

Viewed 131

I would like to use GoogleSignIn and send email using android internal email address (gmail)

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
  //.requestIdToken(getString(R.string.default_web_client_id))
  .requestEmail()
  .requestScopes(new Scope(GmailScopes.GMAIL_SEND) )
  .build();

// Build a GoogleSignInClient with the options specified by gso.
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
dependencies {
  implementation 'com.google.api-client:google-api-client:1.23.0'
  implementation 'com.google.oauth-client:google-oauth-client-jetty:1.23.0'
  implementation 'com.google.apis:google-api-services-gmail:v1-rev83-1.23.0'
  // ...
}

I setup in google console API key, for using gmail, and oauth adding my sh1.

  1. I dont know where to put the API key in the app
  2. Sign in with google works fine without

.requestScopes(new Scope(GmailScopes.GMAIL_SEND) )

But when I am adding it, it hangs forever.

1 Answers

in GmailQuickstart quick startguide you have:

    private static final String TOKENS_DIRECTORY_PATH = "tokens";
    private static final String CREDENTIALS_FILE_PATH = "/credentials.json";

.
.
.

private static Credential getCredentials(final NetHttpTransport HTTP_TRANSPORT,Context context, String personId) throws IOException {
    // Load client secrets.
    InputStream in = GmailQuickstart.class.getResourceAsStream(CREDENTIALS_FILE_PATH);
    if (in == null) {
        throw new FileNotFoundException("Resource not found: " + CREDENTIALS_FILE_PATH);
    }

you need to download the credentials.json and put it here:

enter image description here

look here for a full answer on how to integrate Gmail api in android: Use Gmail api for send mail via Android app

Related