googleapicclient连接不正常



我正在尝试连接mgoogleapicclient,遵循本指南。当我调试时,一个小窗口弹出询问我想登录的googleplus帐户。只要我选择我的主帐户并点击确定,它就会停止,什么都不做。没有错误信息,警告,信息,没有任何内容。

我的来源:公共类MainMenu_Activity扩展Activity实现GoogleApiClient。ConnectionCallbacks GoogleApiClient。OnConnectionFailedListener {

    private Button btnStart;
    private Button btnSubmit;
    private Button btnHOF;
    private GoogleApiClient mGoogleApiClient;
    public static int REQUEST_LEADERBOARD = 100;
    // Request code to use when launching the resolution activity
    private static final int REQUEST_RESOLVE_ERROR = 1001;
    // Bool to track whether the app is already resolving an error
    private boolean mResolvingError = false;
    private static final String STATE_RESOLVING_ERROR = "resolving_error";
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mainmenu);
        mResolvingError = savedInstanceState != null
                && savedInstanceState.getBoolean(STATE_RESOLVING_ERROR, false);
        this.mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addApi(Drive.API)
                .addScope(Drive.SCOPE_FILE)
                .addApi(Plus.API)
                .addScope(Plus.SCOPE_PLUS_LOGIN)
                .addScope(Plus.SCOPE_PLUS_PROFILE)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();
    }
    @Override
    protected void onStart() {
        super.onStart();
        if (!mResolvingError) {  // more about this later
            mGoogleApiClient.connect();
        }
    }
    @Override
    protected void onStop() {
        mGoogleApiClient.disconnect();
        super.onStop();
    }
    @Override
    public void onConnected(Bundle connectionHint) {
        // Connected to Google Play services!
        // The good stuff goes here.
        System.out.println("CONNECTED!");
    }
    @Override
    public void onConnectionSuspended(int cause) {
        // The connection has been interrupted.
        // Disable any UI components that depend on Google APIs
        // until onConnected() is called.
        System.out.println("SUSPENDED!");
    }
    @Override
    public void onConnectionFailed(ConnectionResult result) {
        System.out.println("Connection Failed - mResolvingError=" + mResolvingError);
        if (mResolvingError) {
            System.out.println("Connection Failed - Already attempting to resolve...");
            // Already attempting to resolve an error.
            return;
        } else if (result.hasResolution()) {
            System.out.println("Connection Failed - resolving now...");
            try {
                mResolvingError = true;
                result.startResolutionForResult(this, REQUEST_RESOLVE_ERROR);
            } catch (IntentSender.SendIntentException e) {
                System.out.println("Connection Failed - Exception...");
                // There was an error with the resolution intent. Try again.
                mGoogleApiClient.connect();
            }
        } else {
            // Show dialog using GooglePlayServicesUtil.getErrorDialog()
            Dialog errDia = GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), this, 1);
            errDia.show();
            mResolvingError = true;
        }
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_RESOLVE_ERROR) {
            mResolvingError = false;
            if (resultCode == RESULT_OK) {
                // Make sure the app is not already connected or attempting to connect
                if (!mGoogleApiClient.isConnecting() &&
                        !mGoogleApiClient.isConnected()) {
                    mGoogleApiClient.connect();
                }
            }
        }
    }
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putBoolean(STATE_RESOLVING_ERROR, mResolvingError);
    }
  }
如您所见,我标记了某些地方以遵循该过程。下面是logcat记录的内容:

06-02 17:52:48.175 2302-2302/com. dudewithfacia.game。gamebase I/system . out:连接失败- mResolvingError=false 06-02 17:52:48.175
2302 - 2302/com.dudewithfacial.game。gamebase I/系统。out:连接失败解决现在…

我一步一步地遵循指南:(显然不是真的,我做错了什么stack overflow- guru ?谢谢孩子们,真的很感激!

NVM,发现我不能使用Launchmode, SingleUser, SingleInstance。也没有配置一些请求的api,如"。addapi (Plus.API)"。"

固定问题。

相关内容

  • 没有找到相关文章

最新更新