【问题标题】:GoogleApiClient cant connect to APIGoogleApiClient 无法连接到 API
【发布时间】:2015-03-18 07:11:17
【问题描述】:

我正在尝试测试我的第一个 google Api 应用程序。我正在使用 google play 服务客户端库连接到 google+ API。我做了一个简单的连接,在我的 genymotion 4.4.4(包括谷歌应用程序)中运行它后,一条 toast 消息说 - “发生内部错误”,logcat 也没有显示错误。我添加了互联网、帐户和清单中的凭据。我在控制台中很好地集成了 SHA1 和项目包,在here 中添加了播放服务版本等的元数据,添加了 compile 'com.google.android.gms:play-services-plus: 6.5.87' 在 gradle 中。 我正在使用最新的 android studio。 这是我的代码-

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");  
    }


}

这是我的控制台(它只是一个测试应用,所以没什么可隐藏的)

【问题讨论】:

  • 这通常发生在您尚未在您的API console 项目中为client ID 设置签名或者您使用来自keytool 的错误键值时。所以检查你是否在Developer Console中正确填写了所有必要的字段
  • 谢谢你,但我的控制台可能出了什么问题,请参阅我的控制台图片。我在调试模式下得到了 SHA1。包名也可以...可能是什么问题。请帮助
  • 检查API&AUTHS部分并仔细检查SHA1CliendID
  • 请勿在 emulator.test 中测试。
  • 兄弟这是 emulator.test,没听说过.. :P

标签: android google-plus google-play-services google-client


【解决方案1】:

我找到了解决方案。我很久以前更改了我的 .android 的默认位置,我的 PC 中有两个操作系统和两个 Android 工作室。因此,我发现我从错误的调试密钥库中获取了证书。叹!!我为此浪费了 3 天时间……但对于那些可能没有相同问题的人,请检查您的谷歌控制台选项卡中的同意屏幕,看看是否提到了产品名称和电子邮件地址。它也可能导致同样的错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-08
    • 1970-01-01
    • 1970-01-01
    • 2019-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多