GameHelper登录失败但不是GoogleAPIClient的登录

时间:2014-07-28 13:47:46

标签: android google-play-services google-play-games

我一直在努力使用GameHelper对象来连接GooglePlayServices。打开我的应用程序后,我收到“Google Play服务未知问题”弹出窗口,并且登录错误代码为8.我原本认为这是我设置Google Play服务帐户的方式有问题,但重新创建后会有一些问题时间,并确保一切都在检查,我开始认为这是其他的东西。

所以我尝试设置一个单独的GoogleApiClient来配合GameHelper对象(即使它提供了自己的对象),并且该客户端登录就好了,尽管错误消息仍然从GameHelper对象中弹出。所以我取出了GameHelper对象,但GoogleApiClient无法再次登录。

我想使用其中一个而不是两个,但似乎如果我只使用其中一个对象,它将无法使用。对于GameHelper或GoogleApiClient,我是否需要设置不同的东西才能让它们中的任何一个独立工作?

以下是代码:

public class MyHomeActivity extends FragmentActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {

private GameHelper gameHelper;
private GoogleApiClient client;

@Override
public void onCreate(Bundle savedInstanceState) {

private void setupGooglePlayServices() {
    client = new GoogleApiClient.Builder(this)
            .addApi(Games.API)
            .addScope(Games.SCOPE_GAMES)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

    GameHelper.GameHelperListener gameHelperListener = new GameHelper.GameHelperListener() {
        @Override
        public void onSignInFailed() {
            Log.i("Game Helper", "Sign in failed");
        }

        @Override
        public void onSignInSucceeded() {
            Log.i("Game Helper", "Sign in succeeded");
        }
    };

    gameHelper = new GameHelper(this, GameHelper.CLIENT_GAMES);
    //TODO Remove this for production
    gameHelper.enableDebugLog(true);

    gameHelper.setup(gameHelperListener);
}

@Override
protected void onStart() {
    super.onStart();
    gameHelper.onStart(this);
    client.connect();
}
@Override
protected void onStop() {
    super.onStop();
    gameHelper.onStop();
    client.disconnect();
}

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

@Override
public void onConnected(Bundle bundle) {
    Log.i("Google API", "Connection Complete");
}

@Override
public void onConnectionSuspended(int i) {

}

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
    Log.i("Google API", "Connection Failed: " + connectionResult.toString());
}

的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="my.app.package"
      android:versionCode="2"
      android:versionName="1.0.1">

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="18" />

<application
    android:name=".MyApplication"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity android:name=".MyHomeActivity"
              android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="com.google.android.gms.ads.AdActivity"
              android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
    <meta-data android:name="com.google.android.gms.version"
               android:value="@integer/google_play_services_version" />
    <meta-data android:name="com.google.android.gms.games.APP_ID"
               android:value="@string/google_play_id" />
    <meta-data android:name="com.google.android.gms.appstate.APP_ID"
               android:value="@string/google_play_id" />
</application>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />


</manifest>

日志

D/GameHelper﹕ GameHelper: Debug log enabled.
D/GameHelper﹕ GameHelper: Setup: requested clients: 1
D/GameHelper﹕ GameHelper: onStart
D/GameHelper﹕ GameHelper: Connecting client.
I/Google API﹕ Connection Complete  <-- This is my log telling me the GoogleApiClient connected
D/GameHelper﹕ GameHelper: onConnectionFailed
D/GameHelper﹕ GameHelper: Connection failure:
D/GameHelper﹕ GameHelper:    - code: INTERNAL_ERROR(8)
D/GameHelper﹕ GameHelper:    - resolvable: false
D/GameHelper﹕ GameHelper:    - details: ConnectionResult{statusCode=INTERNAL_ERROR,     resolution=null}
D/GameHelper﹕ GameHelper: onConnectionFailed: WILL resolve because we have below the max# of attempts, 0 < 3
D/GameHelper﹕ GameHelper: onConnectionFailed: resolving problem...
D/GameHelper﹕ GameHelper: resolveConnectionResult: trying to resolve result: ConnectionResult{statusCode=INTERNAL_ERROR, resolution=null}
D/GameHelper﹕ GameHelper: resolveConnectionResult: result has no resolution. Giving up.
W/GameHelper﹕ disconnect() called when client was already disconnected.
D/GameHelper﹕ GameHelper: Notifying LISTENER of sign-in FAILURE (error)
D/GameHelper﹕ GameHelper: onStop
D/GameHelper﹕ GameHelper: Client already disconnected when we got onStop.

2 个答案:

答案 0 :(得分:4)

好吧,我想出来了,这是其中一个“认真?那就是它?”时刻。要通过Google Play服务进行身份验证,您需要在Google Play开发者控制台中启用云端硬盘APK和云端硬盘SDK。如果我从我的logcat中取出过滤器,我会看到以下错误:

07-30 13:00:28.719    2487-2587/? E/Volley﹕ [260] tm.a: Unexpected response code 404 for https://www.googleapis.com/drive/v2internal/files/1hV5vzTnhxozzjUvSgct8oUmqdha4xkiF-K_vDD8BEha8aoc6oZLklxxgZmMVHY46C6uzZzk?prettyPrint=false...
07-30 13:00:43.406    2487-3187/? E/DriveAsyncService﹕ Authorization has been revoked by the user. Reconnect the Drive API client to reauthorize.

启用Google Drive API后,它就像魅力一样。我不确定这方面的文件在哪里,但这是我的答案。

答案 1 :(得分:3)

我遇到了同样的问题,确实是Drive API ...... 转到https://console.developers.google.com将其激活