我有一个应用程序,我已经实现了谷歌+登录。我检查了所有的代码,并在dubugging后发现它总是在onConnectionFailed(ConnectionResult结果)中抛出一个错误,其结果如下所示:
$db = JFactory::getDBO();
$query = "SHOW COLUMNS FROM `#__facets` LIKE 'filters'";
$db->setQuery($query);
$res = $db->loadResult();
代码: -
ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{425b8550: android.os.BinderProxy@423ec2e8}, message=null}
答案 0 :(得分:0)
您可以尝试以下代码: 首先,您需要将GoogleApi初始化为:
private void googleInitialization() {
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
mGoogleApiClient.connect();
}
之后你需要像这样调用这个方法: -
googleInitialization();
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
并且OnActivityResult中的句柄有一个 CallBackManager ,这对于调用登录按钮非常有用
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
}
}
现在,获得以下方法的结果:
private void handleSignInResult(GoogleSignInResult result) {
Log.d("handleSignInResult", "handleSignInResult:" + result.isSuccess());
if (result.isSuccess()) {
// Signed in successfully, show authenticated UI.
GoogleSignInAccount acct = result.getSignInAccount();
String personName = acct.getDisplayName();
String email = acct.getEmail();
if (personName.contains(" ")) {
String fname = personName.substring(0, personName.lastIndexOf(" ") + 1);
String lname = personName.substring(personName.lastIndexOf(" ") + 1);
Log.e("First name", fname);
Log.e("Last name", lname);
} else
String fname = personName;
Log.e("Profile Info", "Name: " + personName + ", email: " + email);
}
}