无法与googleApiClient连接

时间:2014-10-15 09:47:25

标签: android google-api google-plus

我正在尝试为我的应用程序执行g plus注册。启用了api,生成了sha,并在开发人员网站上启用了深层链接。 但是,当我尝试连接时,我无法进行.Logging mGoogleApiCLient.isConnected()始终返回false 这是我使用的代码:

public class GoogleSignUpActivity extends Activity implements
    ConnectionCallbacks, OnConnectionFailedListener {

private static final int REQUEST_CODE_SIGN_IN = 1;
private static final int REQUEST_CODE_GET_GOOGLE_PLAY_SERVICES = 2;

private GoogleApiClient mGoogleApiClient;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this).addApi(Plus.API)
            .addScope(Plus.SCOPE_PLUS_LOGIN).build();
}

@Override
public void onStart() {
    super.onStart();
    mGoogleApiClient.connect();
    Log.i("conn", mGoogleApiClient.isConnected() + "");
}

@Override
public void onStop() {
    mGoogleApiClient.disconnect();
    super.onStop();
}




@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE_SIGN_IN
            || requestCode == REQUEST_CODE_GET_GOOGLE_PLAY_SERVICES) {
        if (resultCode == RESULT_OK && !mGoogleApiClient.isConnected()
                && !mGoogleApiClient.isConnecting()) {
            // This time, connect should succeed.
            mGoogleApiClient.connect();
        }
    }
}

@Override
public void onConnected(Bundle connectionHint) {
    if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
        Person currentPerson = Plus.PeopleApi
                .getCurrentPerson(mGoogleApiClient);
        String personName = currentPerson.getDisplayName();
        // String personPhoto = currentPerson.getImage();
        String personGooglePlusProfile = currentPerson.getUrl();
        Log.i("name", personName);
    }
}

public void onDisconnected() {
    mGoogleApiClient.connect();
}

@Override
public void onConnectionFailed(ConnectionResult result) {
}

@Override
public void onConnectionSuspended(int arg0) {
    // TODO Auto-generated method stub

}

}

提前致谢

1 个答案:

答案 0 :(得分:0)

这对我有用,请尝试,如果你还没有检查.. 在"同意屏幕"中填写电子邮件地址产品名称; Google API Console