我想使用 GoogleSignIn 并使用 android 内部电子邮件地址 (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'
// ...
}
我在 google 控制台 API 密钥中设置,用于使用 gmail,并在 oauth 中添加我的 sh1。
- 我不知道将 API 密钥放在应用程序中的何处
- 使用 google 登录可以正常工作,无需
.requestScopes(新范围(GmailScopes.GMAIL_SEND))
但是当我添加它时,它永远挂起。
在 GmailQuickstart 快速入门指南中,您有:
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);
}
您需要下载credentials.json并将其放在这里:
在这里查看有关如何在 Android 中集成 Gmail api 的完整答案:使用 Gmail api 通过 Android 应用程序发送邮件 https://stackoverflow.com/questions/64156140/use-gmail-api-for-send-mail-via-android-app/68777134#68777134
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)