简体   繁体   English

GoogleApiClient无法连接到API

[英]GoogleApiClient cant connect to API

I m trying to test my first google Api app. 我正在尝试测试我的第一个Google Api应用。 I m using google play service client lib to connect to google+ API. 我正在使用Google Play服务客户端库连接到Google+ API。 I made a simple connection, After I run it in my genymotion 4.4.4 (includes google app), a toast message says- "an internal error occurs", The logcat shows no error either.I added the permission for internet,accounts and credential in manifest.I integrated the SHA1 and project package well in console, added the meta data for play service version etc as in here ,added compile ' com.google.android.gms:play-services-plus:6.5.87 ' in gradle. 我做了一个简单的连接,在我的genymotion 4.4.4(包括google app)中运行它之后,一条吐司消息说:“发生内部错误”,logcat也没有显示错误。我添加了对Internet,帐户和我在控制台中很好地集成了SHA1和项目包,添加了播放服务版本等的元数据,如此处所示, 在其中添加了compile'c​​om.google.android.gms:play-services-plus:6.5.87 '摇篮。 I m using android studio latest. 我正在使用最新的android studio。 THis is my code- 这是我的代码-

public class MainActivity extends FragmentActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
           private GoogleApiClient mClient;
        // Bool to track whether the app is already resolving an error
        private boolean mResolvingError = false;



 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);

        // Create a GoogleApiClient instance for google+
        mClient = new GoogleApiClient.Builder(this)
                .addApi(Plus.API)
                .addScope(Plus.SCOPE_PLUS_LOGIN)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();    
    }

    @Override
    protected void onStart() {
        super.onStart();
        if (!mResolvingError) {  
            mClient.connect();
        }
    }

    @Override
    protected void onStop() {
        mClient.disconnect();
        super.onStop();
    }

    @Override
    public void onConnected(Bundle bundle) {
    // this shows a string log message but it shows nothing
        L.m(" I M CONNECTED");  
    }

    @Override
    public void onConnectionSuspended(int i) {

    }

    @Override
    public void onConnectionFailed(ConnectionResult result) {
// this shows a string log message AND IT SHOWS UP
        L.m(" I M NOT CONNECTED");  
    }


}

This is my console (its just a test app, so nothing to hide) 这是我的控制台(它只是一个测试应用程序,所以没有什么可隐藏的) 在此处输入图片说明

I found the solution. 我找到了解决方案。 I changed the default location of my .android a long ago and there are two OS in my PC with two Android studio. 很久以前,我更改了.android的默认位置,并且PC上有两个带有两个Android studio的操作系统。 Hence, I found that I was getting the certificate from the WRONG debug keystore. 因此,我发现我是从WRONG调试密钥库中获取证书的。 Sigh!! 叹!! I wasted 3 days for this ... but for those of whom who may not have the same issue, check the consent screen in ur google console tab, see if product name and email address are mentioned. 我为此浪费了3天的时间...但是对于那些可能没有相同问题的人,请检查google控制台选项卡中的同意屏幕,看看是否提到了产品名称和电子邮件地址。 It may also result in the same error. 它也可能导致相同的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM