我想将 Gmail API 集成到 Android 应用程序中。到目前为止,该应用程序包含以下步骤:
我想摆脱第3步,因为我的用户刚刚选择了他想要使用的帐户,重新选择它是多余的,但我不能。我尝试设置
login_hint: email
,但是没有效果。
我在这里留下启动同意屏幕的云功能的代码片段:
const scopes = [
'https://www.googleapis.com/auth/gmail.modify'
];
console.log(`Request body: ${request.body.data}`);
admin.auth().verifyIdToken(request.body.data)
.then((decodedToken) => {
const uid = decodedToken.uid;
const email = decodedToken.email;
const sub = decodedToken.sub;
console.log(`Logged in email ${email}`)
const authorizationUrl = oauth2Client.generateAuthUrl({
access_type: 'offline',
scope: scopes,
include_granted_scopes: true,
state: uid,
prompt: "consent",
login_hint: email
});
response.set('Cache-Control', 'private, max-age=0, s-maxage=0');
response.send({"data": authorizationUrl});
})
根据之前的评论发布为社区维基:
应该可以工作,但我不确定是否适用于 Android。有更好的方法,例如developers.google.com/identity/android-credential-manager。login_hint