我正在尝试与谷歌签约。当我不使用requestTokenId的时候,它工作得很好,但是当我使用的时候,我无法登录。
逻辑猫:
D/GoogleLoginCallBackHand: handleSignInResult:false
D/GoogleLoginCallBackHand: handleSignInResult:12500:null在模拟器和每个版本的设备上得到相同的问题。
公共类LoginFragment扩展片段{
// Communicator object to communicate with word outside this Fragment
// Fragments relies on host activity to communicate to outside world
// Hence the host activity should set it
Communicator communicator;
// Google Sign
public SignInButton googleLoginButton;
private GoogleApiClient mGoogleApiClient;
private GoogleLoginCallBackHandler googleLoginCallBackHandler;
//Boolean Variable to track if user is trying to loginWith Google
private boolean mResolvingError = false;
public LoginFragment(){
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setUpGoogleLogin();
}
private void setUpGoogleLogin() {
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestIdToken("876227381632-k7dittplmjrhechqr0fr7dk3ro8frrte.apps.googleusercontent.com")
.build();
googleLoginCallBackHandler = new GoogleLoginCallBackHandler(this);
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.enableAutoManage(getActivity(), googleLoginCallBackHandler)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
}
@Override
public void onStart() {
super.onStart();
super.onStart();
if (!mResolvingError) { // more about this later
mGoogleApiClient.connect();
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_login, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// Google Login Call back set up
googleLoginButton = (SignInButton)view.findViewById(ViewIds.GOOGLE_SIGNIN_BUTTON.getId());
googleLoginButton.setOnClickListener(googleLoginCallBackHandler);
}
@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 == googleLoginCallBackHandler.getRcSignIn()) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
googleLoginCallBackHandler.handleSignInResult(result);
}
}
@Override
public void onResume() {
super.onResume();
}
@Override
public void onStop() {
if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}
super.onStop();
}
public GoogleApiClient getmGoogleApiClient() {
return mGoogleApiClient;
}
public boolean ismResolvingError() {
return mResolvingError;
}
public void setmResolvingError(boolean mResolvingError) {
this.mResolvingError = mResolvingError;
}
/**
* Interface object to communicate with parent activity
* Fragments relies on host activity to communicate to outside world
* Hence the host activity should implement this interface
*/
public interface Communicator{
void communicate();
}
public void setCommunicator(Communicator communicator){
this.communicator = communicator;
}}
发布于 2016-01-29 05:03:29
我认为这可能是由于错误的开发控制台注册。确保在相同的开发控制台项目中,两者都有:
确保在您的Android客户机中传递#2的OAuth2客户端id。
https://stackoverflow.com/questions/33969820
复制相似问题