谷歌加登录,安卓登录提示反复出现

3

我是一名新手安卓开发者。我正在将Google+登录集成到我的应用中,但我对于Google的登录提示反复出现感到有些困惑。我不知道为什么,是我的问题吗?

我正在遵循Google开发者网站上的指导来完成这个任务。我已经使用了多个Google账户测试过我的应用,其中两个账户正常工作,但其他账户没有。


2
请添加您的代码,以便我们能够帮助您。 - Renato Probst
4个回答

1

你尝试过了吗:

如何调试Google+集成?

通过启用日志记录,您可以在使用Google API时诊断网络问题。

要启用日志记录,请运行以下命令:

adb shell setprop log.tag.GooglePlusPlatform VERBOSE

要禁用日志记录,请运行以下命令:

adb shell setprop log.tag.GooglePlusPlatform ""

您需要添加的权限:

访问 Google+ API:

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

为了在登录过程中检索账户名(电子邮件):

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

用于检索OAuth 2.0令牌或使令牌失效以断开用户连接。此断开选项是为了遵守Google+登录开发者政策而必需的:

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

看看是否有帮助。


你好@Gaurav Dave。你能告诉我这是什么权限问题吗..?我使用了2个Google帐户进行测试,在一个帐户中它可以正常运行,但在另一个电子邮件中无法工作...所以我告诉你有权限问题。除了Google Plus API(我已经检查过Google项目控制台API),还有其他需要激活的东西吗? - biswajitGhosh
在使用G+时,您是否已添加了这些权限? - Gaurav Dave
是的,当我创建这个应用程序时,我确实是。 - biswajitGhosh
让我们在聊天中继续这个讨论 - biswajitGhosh
不好意思,我无法复制这个问题。在Android 4.4.2中有太多的日志,很难找到确切的点。我认为我不是第一个遇到这种情况的人,你遇到了吗?你是如何解决这个问题的,可以和我分享一下吗...拜托了,感谢一直陪伴着我。 - biswajitGhosh
显示剩余5条评论

1
protected void onStart() {
        super.onStart();
        mGoogleApiClient.connect();
    }

    protected void onStop() {
        super.onStop();
        if (mGoogleApiClient.isConnected()) {
            mGoogleApiClient.disconnect();
        }
    }


onCreate(Bundle bundle){
mGoogleApiClient = new GoogleApiClient.Builder(YourActivity.this)
                .addConnectionCallbacks(YourActivity.this)
                .addOnConnectionFailedListener(YourActivity.this).addApi(Plus.API)
                .addScope(Plus.SCOPE_PLUS_LOGIN).build();
}



btn_gpluslogin.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        signInWithGplus();
                    }
                });

private void signInWithGplus() {
        if (!mGoogleApiClient.isConnecting()) {
            mSignInClicked = true;
            resolveSignInError();
        }
    }

private void resolveSignInError() {
        if (mConnectionResult.hasResolution()) {
            try {
                mIntentInProgress = true;
                mConnectionResult.startResolutionForResult(this, RC_SIGN_IN);
            } catch (IntentSender.SendIntentException e) {
                mIntentInProgress = false;
                mGoogleApiClient.connect();
            }
        }
    }

    @Override
    public void onConnectionFailed(ConnectionResult result) {
        if (!result.hasResolution()) {
            GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), this,
                    0).show();
            return;
        }

        if (!mIntentInProgress) {
            // Store the ConnectionResult for later usage
            mConnectionResult = result;

            if (mSignInClicked) {
                // The user has already clicked 'sign-in' so we attempt to
                // resolve all
                // errors until the user is signed in, or they cancel.
                resolveSignInError();
            }
        }

    }

@Override
    public void onConnected(Bundle arg0) {
        mSignInClicked = false;
        Toast.makeText(this, "User is connected!", Toast.LENGTH_LONG).show();

        // Get user's information
        SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", 0); // 0 - for private mode
        boolean isSignedUp = pref.getBoolean("isSignedUp", false);
        if (!isSignedUp)
            getGProfileInformation();

        // Update the UI after signin
    }

private void updateUI(boolean isSignedIn) {
        if (isSignedIn) {
            getGProfileInformation();
        } else {
            btn_gpluslogin.setVisibility(View.VISIBLE);
        }
    }

    /**
     * Fetching user's information name, email, profile pic
     */
    private void getGProfileInformation() {
        try {
            if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
                Person currentPerson = Plus.PeopleApi
                        .getCurrentPerson(mGoogleApiClient);
                Log.d("Google Info", currentPerson.toString());
                String personName = currentPerson.getDisplayName();
                String email = Plus.AccountApi.getAccountName(mGoogleApiClient);

            } else {
                Toast.makeText(getApplicationContext(),
                        "Person information is null", Toast.LENGTH_LONG).show();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

0
这是我打赌正在发生的事情。 在 `onConnectionFailed` 中,您正在从 `connectionResult` 开始解决方案。 然后启动 Activity 来解决失败,并应将结果返回到 `onActivityResult`。 但是,您需要确保不要陷入解决循环中。 所以在 `onConnectionFailed` 中,做这个:
private boolean mIsResolving = false;
// ...
public void onConnectionFailed(ConnectionResult connectionResult) {
  if (connectionResult.hasResolution() && !mIsResolving) {
    mIsResolving = true;
    connectionResult.startResolutionForResult(this, RC_SIGN_IN);
  }
}

然后在onActivityResult中执行以下操作:

public void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);
  if (requestCode == RC_SIGN_IN) {
    if (resultCode == RESULT_OK) {
      mIsResolving = false;
      mGoogleApitClient.connect();
    } else {
      // ...
    }
  }
}

0

由于您没有提供任何代码,让我来猜测一下。如果您说您在某些帐户上遇到了问题而在其他帐户上没有问题,那么我认为这些有问题的帐户还没有授权您的应用程序。请检查以下配置(在浏览器中登录后):

https://security.google.com/settings/security/permissions?pli=1

还是这个?

https://plus.google.com/u/0/apps

在列表中查找您的应用程序。也许您的权限被拒绝了或者其他原因。也许您只需要再次授权、重置并重试。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接