首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google在Android requestTokenId中注册

Google在Android requestTokenId中注册
EN

Stack Overflow用户
提问于 2015-11-28 09:36:55
回答 1查看 816关注 0票数 1

我正在尝试与谷歌签约。当我不使用requestTokenId的时候,它工作得很好,但是当我使用的时候,我无法登录。

逻辑猫:

代码语言:javascript
复制
D/GoogleLoginCallBackHand: handleSignInResult:false

D/GoogleLoginCallBackHand: handleSignInResult:12500:null

在模拟器和每个版本的设备上得到相同的问题。

公共类LoginFragment扩展片段{

代码语言:javascript
复制
// 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;
}

}

EN

回答 1

Stack Overflow用户

发布于 2016-01-29 05:03:29

我认为这可能是由于错误的开发控制台注册。确保在相同的开发控制台项目中,两者都有:

  1. 您的Android客户端:由包名+签名证书SHA1唯一标识(如果您有多个签名证书,例如调试密钥存储库、测试环境证书、生产环境证书,则必须全部注册)
  2. 您的网络类型客户端检查您的OAuth2客户端,转到凭据页并选择您的项目。

确保在您的Android客户机中传递#2的OAuth2客户端id。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33969820

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档