Using Android GoogleSignIn with GmailScopes.GMAIL_SEND (gmail api)(将Android GoogleSignIn与GmailScope配合使用。GMAIL_Send(Gmail API))
问题描述
我想使用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登录时无需 即可正常工作
.questScope(新作用域(GmailScope.GMAIL_Send))
但当我添加它时,它永远挂起。
推荐答案
在Gmail快速入门指南中,您有:
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);
}
您需要下载redentials.json并放在这里:
如何在Android中集成Gmail API,请查看以下完整答案: Use Gmail api for send mail via Android app
这篇关于将Android GoogleSignIn与GmailScope配合使用。GMAIL_Send(Gmail API)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!