如何在APP中集成Google账户登录
谷歌账号购买交易平台/谷歌邮箱新老号-自动购买
2004年/2008年/2011年/2018年/2019年/2020年/2021年/2022年谷歌号购买
Google Play地区更改/锁区号购买
Youtube老频道号购买
美国苹果id/日本苹果id/韩国苹果id/台湾苹果ID/香港苹果ID/新加坡苹果ID购买
shadowrocket可下载小火箭账号/美区小火箭下载账号购买
下图是谷歌账号登录流程图:
如果您在 APP 中使用您的 Google 帐户登录。
第一步:
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(new Scope(Scopes.DRIVE_APPFOLDER))
// The serverClientId is an OAuth 2.0 web client ID
// Details at: https://developers.google.com/identity/sign-in/android/?utm_campaign=android_discussion_server_021116&utm_source=anddev&utm_medium=blogstart step 4
.requestServerAuthCode(serverClientId)
.requestEmail()
.build();
这需要您的服务器的 Web 客户端 ID。有关如何获取它的详细信息,请参阅第 4 步。
在这种情况下,将请求 DRIVE_APPFOLDER 范围,这意味着将要求用户允许应用访问 Google Drive。此外,服务器将请求验证码。
如果登录成功,验证码可以从账户中提取对象谷歌账号购买微信支付谷歌账号购买微信支付,如下:
此验证码应使用 HTTPS 发送到您的服务器,并在交换后,将让您的服务器访问用户的 Google Drive。(重要提示:您应该向后端发送经过身份验证的代码调用,以确保它是来自活动用户的合法请求)。
第 2 步:您需要使用 GoogleAuthorizationCodeTokenRequest 类:
// Set path to the Web application client_secret_*.json file you downloaded from the
// Google Developers Console: https://console.developers.google.com/project/_/apiui/credential
// You can also find your Web application client ID and client secret from the
// console and specify them directly when you create the GoogleAuthorizationCodeTokenRequest
// object.
String CLIENT_SECRET_FILE = "/path/to/client_secret.json"; // Be careful not to share this!

String REDIRECT_URI = "/path/to/web_app_redirect" // Can be empty if you don’t use web redirects
// Exchange auth code for access token
GoogleClientSecrets clientSecrets =
GoogleClientSecrets.load(
JacksonFactory.getDefaultInstance(), new FileReader(CLIENT_SECRET_FILE));
GoogleTokenResponse tokenResponse =
new GoogleAuthorizationCodeTokenRequest(
new NetHttpTransport(),
JacksonFactory.getDefaultInstance(),
"https://www.googleapis.com/oauth2/v4/token",

clientSecrets.getDetails().getClientId(),
clientSecrets.getDetails().getClientSecret(),
authCode,
REDIRECT_URI)
.execute();
String accessToken = tokenResponse.getAccessToken();
String refreshToken = tokenResponse.getRefreshToken();
Long expiresInSeconds = tokenResponse.getExpiresInSeconds();
// You can also get an ID token from the exchange result if basic profile scopes are requested
// e.g. starting GoogleSignInOptions.Builder from GoogleSignInOptions.DEFAULT_SIGN_IN like the

// sample code as used here: http://goo.gl/0Unpq8
//
// GoogleIdToken googleIdToken = tokenResponse.parseIdToken();
然后,创建一个 GoogleCredential 从GoogleTokenResponse对象使用令牌:
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(new NetHttpTransport())
.setJsonFactory(JacksonFactory.getDefaultInstance())
.setClientSecrets(clientSecrets)

.build();
credential.setAccessToken(accessToken);
credential.setExpiresInSeconds(expiresInSeconds);
credential.setRefreshToken(refreshToken);
如果刷新令牌可用,您可以保留 StoredCredential 的凭据以供以后使用,如果您需要代表用户继续访问 API。
第 3 步:凭据可用于访问 Google 服务。现在,在我们的送餐场景中,您可能希望在 Google Drive 上存储或检索已完成货物的照片或收据。例如,它看起来像这样:
Drive drive = new Drive.Builder(new NetHttpTransport(),
JacksonFactory.getDefaultInstance(),
credential)
.setApplicationName("Auth Code Exchange Demo")
.build();
File file = drive.files().get("appfolder").execute();
谷歌账号购买交易平台/谷歌邮箱新老号-自动购买
2004年/2008年/2011年/2018年/2019年/2020年/2021年/2022年谷歌号购买
Google Play地区更改/锁区号购买
Youtube老频道号购买
美国苹果id/日本苹果id/韩国苹果id/台湾苹果ID/香港苹果ID/新加坡苹果ID购买
shadowrocket可下载小火箭账号/美区小火箭下载账号购买
版权声明:
作者:中州西鹿谷歌
链接:https://www.gmail777.com/archives/1131
来源:中州西鹿
文章版权归作者所有,未经允许请勿转载。

共有 0 条评论