我的应用需要通过Google登录。我从firebase打开了教程(但首先你需要配置Google本身)按照说明中的说明进行了操作。但是,它不起作用。为什么result.isSuccess()总是错误的。因此,我无法获得帐户信息。
logcat的:
08-04 08:32:28.128 1948 1948 D AutoManageHelper starting AutoManage for client 0 false false
08-04 08:32:28.136 1948 1948 D AutoManageHelper onStart true {0=com.google.android.gms.internal.zzqm$zza@efb56ec}
08-04 08:32:28.296 1948 1974 E GED Failed to get GED Log Buf, err(0)
08-04 08:32:35.293 1948 1948 D Tag handleSignInResult:false
代码:
import android.content.*;
import android.os.*;
import android.support.v7.app.*;
import android.view.*;
import android.view.View.*;
import com.google.android.gms.auth.api.*;
import com.google.android.gms.auth.api.signin.*;
import com.google.android.gms.common.api.*;
import android.util.*;
import android.support.v4.app.*;
import com.google.android.gms.common.*;
import android.widget.*;
public class GoogleSigInActivity extends FragmentActivity implements GoogleApiClient.OnConnectionFailedListener
{
GoogleApiClient mGoogleApiClient;
private static final int RC_SIGN_IN = 9001;
private String TAG = "Tag";
TextView mStatusTextView;
@Override
public void onConnectionFailed(ConnectionResult p1)
{
// TODO: Implement this method
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gogle_sign_in);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).
requestEmail().
build();
// Build a GoogleApiClient with access to the Google Sign-In API and the
// options specified by gso.
mGoogleApiClient = new GoogleApiClient.Builder(this).
enableAutoManage(this, this).
addApi(Auth.GOOGLE_SIGN_IN_API, gso).
build();
mStatusTextView = (TextView) findViewById(R.id.activitygoglesigninTextView1);
findViewById(R.id.sign_in_button).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View p1)
{
switch (p1.getId())
{
case R.id.sign_in_button :
signIn();
break;
}
}
});
}
private void signIn()
{
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN)
{
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
}
}
private void handleSignInResult(GoogleSignInResult result)
{
Log.d(TAG, "handleSignInResult:" + result.isSuccess());
if (result.isSuccess())
{
// Signed in successfully, show authenticated UI.
GoogleSignInAccount acct = result.getSignInAccount();
mStatusTextView.setText("work " + acct.getDisplayName());
}
else
{
// Signed out, show unauthenticated UI.
mStatusTextView.setText("not work");
}
}
}
答案 0 :(得分:0)
您应首先检查是否已从API console启用了“Google Play游戏服务”API。这使您的应用可以使用身份验证服务。 对我来说,谷歌登录仅适用于我的应用程序的签名APK,无法使其在调试版本中工作。