首页 文章

google登录中的statusCode = DEVELOPER_ERROR

提问于
浏览
5

我正在使用谷歌登录的代码 . 我在app文件夹中添加了 google-services.json 文件 . 我在根gradle模块中使用 classpath 'com.google.gms:google-services:2.0.0 ' . 我已经在开发者控制台检查了我的软件包并且它正确并且我添加了SHA1密钥,我通过运行命令获得了 keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android 在终端上(我正在使用ubuntu) . 我已经启用了Google API . 我已经创建了OAuth同意屏幕和OAuth客户端ID . 当我尝试使用google登录时,我得到以下错误

{statusCode = DEVELOPER_ERROR,resolution = null}

我检查类似的问题,但找不到合适的解决方案 . 码

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestProfile().requestId()
            .requestEmail().requestScopes(new Scope(Scopes.PLUS_ME))
            .requestScopes(new Scope(Scopes.PLUS_LOGIN))
            .build();
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

    googleButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
    Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
    startActivityForResult(signInIntent, RC_SIGN_IN);

    }
    });

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == RC_SIGN_IN) {
            GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
            handleSignInResult(result);
        } 
    }
    private void handleSignInResult(GoogleSignInResult result) {
        if (result.isSuccess()) {
            // Signed in successfully, show authenticated UI.
            GoogleSignInAccount acct = result.getSignInAccount();

        } else {
            // Signed out, show unauthenticated UI.
            // updateUI(false);
        }
    }
    @Override
    protected void onStart() {
        super.onStart();
        mGoogleApiClient.connect();
    }
    @Override
    protected void onStop() {
        super.onStop();
        if(mGoogleApiClient.isConnected())
        {
            mGoogleApiClient.disconnect();
        }
    }
    @Override
    protected void onResume() {
        super.onResume();
        if(mGoogleApiClient.isConnected())
        {
            mGoogleApiClient.connect();
        }
    }

表现

<uses-permission android:name="android.permission.INTERNET" />
   <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <!-- To use account credentials -->
    <uses-permission android:name="android.permission.USE_CREDENTIALS" />
  <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

6 回答

  • 5

    您的问题很可能是因为您从 ~/.android/debug.keystore 中选择了SHA1,但未使用它来签署您的构建 .

    • 转到模块选项签名选项卡并添加一个配置文件,其中唯一的字段 Store File 设置为 /Users/<your_user>/.android/debug.keystore

    • 在Flavors选项卡上,在 Signing Config 下拉列表中选择它 .

    • 在“构建类型”选项卡上,在 Signing Config 下拉列表中为您的构建类型选择它(可能是 Debug ) .

    • 清理并重建 .

  • 0

    如果您在两台计算机上工作不同,则必须再次生成SHA1并添加到console.firebase.google.com,下载google-service.json并添加到您的项目中

  • 3

    我有同样的问题,this solution已经有效 . 希望这会对你和他人有所帮助 .

    应用插件:'com.android.application'

    android {
        compileSdkVersion 25
        buildToolsVersion "25.0.3"
        defaultConfig {
    

    确保此applicationId与Manifest文件中的包名相同(大写和小写的内容)

    applicationId "com.example" 
            minSdkVersion 17
            targetSdkVersion 25
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
  • 3

    将.requestIdToken(BACKEND_CLIENT_ID)与您的GoogleSignInOptions一起使用 .

    如何获取BACKEND_CLIENT_ID可以在这里找到:https://developers.google.com/identity/sign-in/android/start-integrating#get_your_backend_servers_oauth_20_client_id

    希望这有帮助!

  • 6

    通过在我的应用程序的firebase控制台中添加 debug key storedebug key store 来解决这个问题,当你为 release 进行密钥存储时,在这里 C:\Users\my name.android 更改它在firebase控制台中

  • 5

    感谢Aleksey Gureiev提示...我通过确保在构建期间实际使用调试键来解决我的问题 .

    对于我在Android Studio中的问题是签名配置根本没有设置 . 我仍然想知道它是如何发生的 .

    一旦我将Signing Config设置为名为“debug”的配置,那么一切都开始工作了 .

    enter image description here

相关问题