Android-Google一键登陆/注册-刷新令牌
创始人
2024-08-19 18:30:24
0
  1. 首先在项目级别的 build.gradle 文件中添加以下代码:
dependencies {
    implementation 'com.google.android.gms:play-services-auth:19.0.0'
}
  1. 在需要使用 Google 一键登陆/注册的 Activity 中添加以下代码:
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
        .requestEmail()
        .requestIdToken(getString(R.string.google_web_client_id))
        .build();
GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(this, gso);

其中,R.string.google_web_client_id 为 Google 分配的 Web 应用程序客户端 ID。 3. 在需要实现登陆/注册的地方添加以下代码:

Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);

其中,RC_SIGN_IN 可以自定义请求编码。 4. 在 Activity 中添加 onActivityResult 方法,该方法用于处理 Google 登陆返回的结果:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        Task task = GoogleSignIn.getSignedInAccountFromIntent(data);
        handleSignInResult(task);
    }
}

private void handleSignInResult(Task completedTask) {
    try {
        GoogleSignInAccount account = completedTask.getResult(ApiException.class);

        // Signed in successfully, show authenticated UI.
        updateUI(account);
    } catch (ApiException e) {
        // The ApiException status code indicates the detailed failure reason.
        // Please refer to the GoogleSignInStatusCodes class reference for more information.
        Log.w(TAG, "signInResult:failed code=" + e.getStatusCode());
        updateUI(null);
    }
}
  1. 在需要获取刷新令牌的地方添加以下代码:
private void getRefreshToken(GoogleSignInAccount account) {
    try {
        String refreshToken = account.getRefreshToken();
        Log.d(TAG, "Refresh Token: " + refreshToken);
    } catch (NullPointerException e) {
        Log.e(TAG, "Failed to get Refresh Token: " + e.getMessage());
    }
}

相关内容

热门资讯

透视系统"wepok... 1、透视系统"wepoker新号好一点吗"详细辅助透视教程(私局代打教程);详细教程。2、wepok...
透视安卓版"wepo... 1、透视安卓版"wepokerplus万能挂"详细辅助透明教程(俱乐部辅助器透视)。2、wepoke...
透视黑科技"hhpo... 透视黑科技"hhpoker是内部控制吗"详细辅助解说技巧(透视脚本下载攻略);hhpoker是内部控...
透视黑科技"wepo... 透视黑科技"wepoker轻量版透视方法"详细辅助详细教程(透视脚本免费app攻略)准备好在wepo...
透视了解"aapok... 1、透视了解"aapoker俱乐部靠谱吗"详细辅助透明挂教程(辅助脚本攻略)2、进入游戏-大厅左侧-...
透视了解"hhpok... 透视了解"hhpoker透视方法"详细辅助揭秘攻略(可以挂底牌技巧)1、点击下载安装,微扑克wpk插...
透视app"约局吧开... 透视app"约局吧开挂神器是真的吗"详细辅助第三方教程(有透视方法技巧);最新版2024是一款经典耐...
透视了解"wepok... 透视了解"wepoker私人局俱乐部怎么进"详细辅助爆料教程(有挂神器);实战中需综合运用上述技巧,...
透视软件"wepok... 透视软件"wepoker私人局外卦"详细辅助AI教程(正确养号方法技巧)是一款可以让一直输的玩家,快...
透视脚本"we po... 透视脚本"we poker辅助器v3.3"详细辅助安装教程(辅助器激活码透视)准备好在we poke...