我在https://console.developers.google.com/apis/credentials?project=XXXXX创建了一个项目和一个Android凭据
我按照以下步骤在我的Android应用上添加Google SignIn:https://developers.google.com/identity/sign-in/android/start-integrating#prerequisites
我的第一个疑问是 . 在Google控制台上创建凭据后,如何获取google-services.json文件?我只能下载client_secret_XXXXXXXXXXX-asdfasdfasdfasdfasdfasdf.apps.googleusercontent.com.json
按照Google SignIn指南设置完所有内容后,我无法从Google API获取令牌 . 我发现了这个问题:New Google sign in Android
第一步告诉您创建配置文件(为您创建OAuth 2.0客户端ID并将其插入到google-services.json中)然后,它再次说明了创建OAuth 2.0客户端ID,但这次它说你必须为Web应用程序这样做这是令人困惑的部分! (至少对我来说)因为我只是为Android OAuth创建了客户端ID,而没有为Web应用程序创建一个新的(我认为文档只是冗余或者其他东西)正如它所说的那样,它就是这个,只有这个必须用作方法requestIdToken或requestServerAuthCode的参数 . 忘记在这种方法中使用Android OAuth ID,因为这样你就会得到丑陋的状态代码响应12501.我认为主要的问题是文档有点令人困惑 . 或者也许是因为你必须创建两个OAuth ID这一事实有点奇怪 . 因此,作为摘要,您需要两个OAuth ID,一个用于android,一个用于Web应用程序,您必须将每个ID设置在正确的位置 .
有人说我必须创建一个Web应用程序凭据 . 现在我很困惑,我有2个json文件(client_secret_XXXXXXXXXXX-asdfasdfasdfasdfasdfasdf.apps.googleusercontent.com.json和google-services.json,以及2个客户端ID(Android和Web)
// Configure sign-in to request the user's ID, email address, and basic
// profile. ID and basic profile are included in DEFAULT_SIGN_IN.
String serverClientId = getString(R.string.oauth_client_google);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestIdToken(serverClientId)
.requestProfile()
.build();
// Build a GoogleApiClient with access to the Google Sign-In API and the
// options specified by gso.
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
R.string.oauth_client_google is the Web Application Client ID. If I set the Android Client ID there is not working.
我真的需要Android客户端ID吗?
任何人都知道正确的步骤:首先是谷歌帐户选择器,然后是谷歌的令牌?
1 回答
转到https://developers.google.com/identity/sign-in/android/start配置并按照步骤获取google_services.json . 所有内容都清楚地写在那里 . 客户秘密不是必需的 . 将google_services.json文件保留在您的app文件夹中 .
然后在你的活动中声明
之后在onCreate方法中编写
并继续谷歌文档https://developers.google.com/identity/sign-in/android/sign-in#add_the_google_sign-in_button_to_your_app