登錄失敗。請檢查您的網絡連接並再次嘗試

[英]Failed to sign in. Please check your network connection and try again


I am trying to make simple game with Google Play Games Services, but I failed to sign in to Google Play Games.

我正在嘗試用谷歌做一個簡單的游戲玩服務,但是我沒有注冊到谷歌玩游戲。

I get this error:

我得到這個錯誤:

Failed to sign in. Please check your network connection and try again.

登錄失敗。請檢查您的網絡連接並再次嘗試。

I have MainActivity, and three fragmenets (MainFragment, GameFragment and ResultFragment).

我有主活動,和三個片段(主片段,游戲片段和結果片段)。

MainFragment is fragment for main menu, where use have button to click to start the game.

主片段是主菜單的片段,使用按鈕點擊開始游戲。

Authorization?

授權?

I have linked and authorized my game with SHA-1 in Google Play Developer Console.

我已經將我的游戲與SHA-1鏈接並授權給谷歌的Play Developer控制台。

As I use Android Studio my package name looks something like: aplikacijezaandroid.thebuttonchallenge, and I added two app version in linked apps on Google Play Developer Console.

當我使用Android Studio時,我的包名看起來像:aplikacijezaandroid。thebuttonchallenge,我在谷歌的開發者控制台上添加了兩個應用程序版本。

So I have com.aplikacijezaandroid.thebuttonchallenge, and aplikacijezaandorid.thebuttonchallenge

所以我有com.aplikacijezaandroid。thebuttonchallenge,aplikacijezaandorid.thebuttonchallenge

App ID?

應用程序ID嗎?

I added app id, and leaderboard id into strings.xml and I added meta tag to Android Manifest.

我在字符串中添加了應用程序id和主板id。xml和我在Android Manifest中添加了meta標記。

I have added Internet permission in AndroidManifest.xml

我在AndroidManifest.xml中添加了互聯網權限

Testing?

測試?

I test and debug app from Android Studio with physical device and ofc there is my own gmail added as test user in Google Play Developer Console.

我用物理設備和ofc在Android Studio中測試和調試應用程序,我自己的gmail在谷歌游戲開發人員控制台添加了測試用戶。

Here is my AndroidManifest.xml

這是我AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="aplikacijezaandroid.thebuttonchallenge" >

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
   <meta-data android:name="com.google.android.gms.games.APP_ID" android:value="@string/app_id"/>
   <meta-data android:name="com.google.android.gms.version" 

  android:value="@integer/google_play_services_version"/>
  </application>

Here is MainActivity class:

這里是MainActivity類:

 public class MainActivity extends Activity implements MainMenuFragment.Listener,   
 GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, 
 GameFragment.Listener, ResultFragment.Listener {

//Fragments
MainMenuFragment mMainFragment;
GameFragment mGameFragment;
ResultFragment mResultFragment;

// Client used to interact with Google APIs
private GoogleApiClient mGoogleApiClient;

// Are we currently resolving a connection failure?
private boolean mResolvingConnectionFailure = false;

// Has the user clicked the sign-in button?
private boolean mSignInClicked = false;

// Automatically start the sign-in flow when the Activity starts
private boolean mAutoStartSignInFlow = true;

// request codes we use when invoking an external activity
private static final int RC_RESOLVE = 5000;
private static final int RC_UNUSED = 5001;
private static final int RC_SIGN_IN = 9001;

//Debug
private String TAG = "IGRA";

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

    // Create the Google API Client with access to Plus and Games
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
            .addApi(Games.API).addScope(Games.SCOPE_GAMES)
            .build();

    //Fragments
    mMainFragment = new MainMenuFragment();
    mGameFragment = new GameFragment();
    mResultFragment = new ResultFragment();

    // listen to fragment events
    mMainFragment.setListener(this);
    mGameFragment.setListener(this);
    mResultFragment.setListener(this);

    //Treba dodati listenere


    // add initial fragment (welcome fragment)
    if (savedInstanceState == null) {
        getFragmentManager().beginTransaction().add(R.id.container, mMainFragment).commit();
    }
}

// Switch UI to the given fragment
void switchToFragment(Fragment newFrag) {
    getFragmentManager().beginTransaction().replace(R.id.container, newFrag)
            .commit();
}

private boolean isSignedIn() {
    return (mGoogleApiClient != null && mGoogleApiClient.isConnected());
}

@Override
protected void onStart() {
    super.onStart();
    Log.d(TAG, "onStart(): connecting");
    mGoogleApiClient.connect();
}

@Override
protected void onStop() {
    super.onStop();
    Log.d(TAG, "onStop(): disconnecting");
    if (mGoogleApiClient.isConnected()) {
        mGoogleApiClient.disconnect();
    }
}

@Override
public void onStartGameRequested() {
    startGame();
}

@Override
public void onShowAchievementsRequested() {

}

@Override
public void onShowLeaderboardsRequested() {

}

void startGame(){
    switchToFragment(mGameFragment);
}

public void onEnteredScore(int finalScore){

    mResultFragment.setFinalScore(finalScore);

    // push those accomplishments to the cloud, if signed in
    pushAccomplishments(finalScore);

    // switch to the exciting "you won" screen
    switchToFragment(mResultFragment);
}

private void pushAccomplishments(int finalScore) {

    if (!isSignedIn()) {
        // can't push to the cloud, so save locally
       // mOutbox.saveLocal(this);
        Log.d(TAG, "can't push to the cloud, so save locally");
        return;
    }
    Games.Leaderboards.submitScore(mGoogleApiClient,   getString(R.string.number_guesses_leaderboard),
            finalScore);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

@Override
public void onConnected(Bundle bundle) {
    Log.d(TAG, "onConnected(): connected to Google APIs");
    // Show sign-out button on main menu
    //mMainFragment.setShowSignInButton(false);

    // Show "you are signed in" message on win screen, with no sign in button.
    //mWinFragment.setShowSignInButton(false);

    // Set the greeting appropriately on main menu
    Player p = Games.Players.getCurrentPlayer(mGoogleApiClient);
    String displayName;
    if (p == null) {
        Log.w(TAG, "mGamesClient.getCurrentPlayer() is NULL!");
        displayName = "???";
    } else {
        displayName = p.getDisplayName();
    }
    mMainFragment.setGreeting("Hello, " + displayName);


    // if we have accomplishments to push, push them
    /*if (!mOutbox.isEmpty()) {
        pushAccomplishments();
        Toast.makeText(this, getString(R.string.your_progress_will_be_uploaded),
                Toast.LENGTH_LONG).show();
    }*/
}

@Override
public void onWinScreenDismissed() {
    switchToFragment(mMainFragment);
}

@Override
public void onWinScreenSignInClicked() {

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    if (requestCode == RC_SIGN_IN) {
        mSignInClicked = false;
        mResolvingConnectionFailure = false;
        if (resultCode == RESULT_OK) {
            mGoogleApiClient.connect();
        } else {
            BaseGameUtils.showActivityResultError(this, requestCode, resultCode,
                    R.string.signin_failure, R.string.signin_other_error);
        }
    }
}

@Override
public void onConnectionSuspended(int i) {
    Log.d(TAG, "onConnectionSuspended(): attempting to connect");
    mGoogleApiClient.connect();
}

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
    Log.d(TAG, "onConnectionFailed(): attempting to resolve");
    if (mResolvingConnectionFailure) {
        Log.d(TAG, "onConnectionFailed(): already resolving");
        return;
    }

    if (mSignInClicked || mAutoStartSignInFlow) {
        mAutoStartSignInFlow = false;
        mSignInClicked = false;
        mResolvingConnectionFailure = true;
        if (!BaseGameUtils.resolveConnectionFailure(this, mGoogleApiClient, connectionResult,
                RC_SIGN_IN, getString(R.string.signin_other_error))) {
            mResolvingConnectionFailure = false;
        }
    }

    // Sign-in failed, so show sign-in button on main menu
    mMainFragment.setGreeting(getString(R.string.signed_out_greeting));
    //mMainMenuFragment.setShowSignInButton(true);
   // mWinFragment.setShowSignInButton(true);
}

6 个解决方案

#1


5  

I have solved this problem, so I will post the answer.

我已經解決了這個問題,所以我將公布答案。

I have moved app id and leaderboard id from strings.xml to ids.xml in values folder.

我已經從字符串中移動了app id和排行榜id。xml id。xml值文件夾中。

I have deleted all client ids and add again client ids for debug keystore and release keystore.

我已經刪除了所有的客戶端id,並再次為調試密鑰存儲庫和釋放密鑰存儲庫添加客戶端id。

#2


4  

In my case the problem was one of gmail accounts (out of two) was not added to the testers accounts at the play store and was the default account for my device.

在我的例子中,問題是gmail帳戶(兩個中有一個)沒有添加到play商店的測試帳戶中,並且是我的設備的默認帳戶。

I removed the account to make the other account (testers account at playstore) default and added it back again, and it started working

我刪除了該帳戶以使其他帳戶(playstore中的測試帳戶)默認為默認值,並再次添加該帳戶,並開始工作

#3


3  

If you haven't published your app/game: After you done every usual step, make sure you test your app/game with a device has only the test account/s. I checked every step a few times and ended with this weird problem. Lastly i tested my app with a device has only test account i added on Developer Console. It worked. Hope, this helps someone else.

如果你還沒有發布你的應用程序/游戲:在你完成所有通常的步驟之后,確保你用一個設備測試你的應用程序/游戲只有測試帳戶/s。我檢查了每一步,最后發現了這個奇怪的問題。最后,我用一個只在開發人員控制台添加了測試帳戶的設備來測試我的應用程序。它工作。希望,這能幫助別人。

#4


0  

In my case.I setted one test account,but my device has an default account which is another,that's why I got this error.My mistake but Why can't google gives us an more obvious error report?

在我的例子中。我設置了一個測試帳戶,但是我的設備有一個默認帳戶,這就是為什么我有這個錯誤。我的錯誤,但是為什么谷歌不能給我們一個更明顯的錯誤報告呢?

Here is how I worked this out.All my test was under debug version using test account. I delete the project, both in google play develper console and google Api console.And recreate one as mentioned by others on stackoverflow.But this does't help.I redo this and ends up in vane.

我是這樣算出來的。我所有的測試都是在調試版本中使用的。我刪除了這個項目,包括谷歌游戲develper控制台和谷歌Api控制台。並像stackoverflow上其他人提到的那樣重新創建一個。但這並沒有幫助。我重做了一遍,結果是葉片。

I cheked found in log these same words:

我在日志里發現了同樣的話:

03-09 16:15:39.897: E/GameAgent(1225): Unable to retrieve application xxxxxxx from network 03-09 16:15:39.902: E/GameAgent(1225): Application ID xxxxxxx is not associated with package com.gyj.pub.gpgsDemo. Check the application ID in your manifest. 03-09 16:15:39.906: E/CheckGameplayAcl(23917): Unable to load metadata for game 03-09 16:15:39.906: W/SignInActivity(23917): onSignInFailed()...

E/GameAgent(1225):無法從網絡03-09 16:15:39.902:E/GameAgent(1225):應用ID xxxxx與package com.gyj.pub.gpgsDemo沒有關聯。檢查清單中的應用程序ID。03-03-0906:E/CheckGameplayAcl(23917):無法載入游戲的元數據(03-09 16:15:39.906:W/SignInActivity(23917): onSignInFailed()…

one more,I checked all the 3 elements below ,decide whether the client apk is conform with Google Play Deverloper Console's configuration. 1.package name .It is all the same. 2.Certification SHA1 fingerprint.(debug and release). 3.test Account.

另外,我檢查了下面的3個元素,確定客戶端apk是否符合谷歌Play Deverloper控制台的配置。1。包名,都是一樣的。2。認證SHA1指紋。(調試和發布)。3所示。測試賬戶。

Even at that time I did not realize that I haven't input an account during my tests,How does the device know which account is attend to sign in? I tried an other account.I added this account which has setted in sonsole as Test Account to the device,relaughched the TypeANumber app.It showed me a view to choose one from the two accounts.Suddently I got it.

即使那時我也沒有意識到在我的測試中我沒有輸入一個賬號,設備是如何知道哪個賬號需要登錄的呢?我嘗試了另一個賬戶。我把放在sonsole上的這個賬號作為測試賬號添加到設備上,重新連接了typeanuts應用程序,顯示了我從兩個賬號中選擇一個的視圖。我忽然明白了。

#5


0  

In my case,I only add a release client ID in Google Play Console. When I run my app by click button RUN in AS,the network connection error show.But when I run the apk generated by the signed,it work well. So, add a debug client id if you want to run your app inside AS.

在我的例子中,我只在谷歌播放控制台添加一個發布客戶端ID。當我通過單擊按鈕運行app時,顯示網絡連接錯誤。但是當我運行簽名生成的apk時,它工作得很好。因此,如果您想在AS內部運行應用程序,請添加調試客戶端id。

#6


0  

For me its that my project SHA1 is not the same as what is in the API console.
1. I've checked mine through this.
2. Went to https://console.developers.google.com and into the "Credentials" page of my project.
3. Clicked on the edit button (the pencil icon) and pasted over the SHA1
4. Worked within <2 minutes

對我來說,我的項目SHA1與API控制台中的不一樣。1。我檢查過我的。2。到https://console.developers.google.com,進入我的項目的“憑證”頁面。3所示。點擊編輯按鈕(鉛筆圖標),粘貼在SHA1 4上。在< 2分鍾


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2014/11/07/725ca00c5ed1760aca4ea86f6294f91a.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com