Java 安卓谷歌&x2B;Api登录不';行不通
我想在我的应用程序中实现Google+Api。因此,我有以下代码:Java 安卓谷歌&x2B;Api登录不';行不通,java,android,google-plus,google-play-services,Java,Android,Google Plus,Google Play Services,我想在我的应用程序中实现Google+Api。因此,我有以下代码: private void googleLogin(){ if(!isConnectingToInternet()){ createInetErrorDialog(); } else{ mPlusClient = new GoogleApiClient.Builder(this) .addApi(Plus.API)
private void googleLogin(){
if(!isConnectingToInternet()){
createInetErrorDialog();
} else{
mPlusClient = new GoogleApiClient.Builder(this)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.addScope(Plus.SCOPE_PLUS_PROFILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
if(mPlusClient != null) {
mPlusClient.connect();
System.out.println("GOOGLE connected");
}
}
}
然后在onConnected中,我执行以下操作:
@Override
public void onConnected(Bundle connectionHint) {
if(mPlusClient.isConnected()) {
if (Plus.PeopleApi.getCurrentPerson(mPlusClient) != null) {
Person person = Plus.PeopleApi.getCurrentPerson(mPlusClient);
currentPersonName = person.getDisplayName();
email = Plus.AccountApi.getAccountName(mPlusClient);
System.out.println("GOOGLE onConnected" + email);
getAccessToken();
} else {
System.out.println("GOOGLE error connection" + Plus.AccountApi.getAccountName(mPlusClient));
}
}
}
问题是它总是运行在else情况下,因为getCurrentPerson返回null。当我第一次启动我的应用程序时,同意屏幕弹出,我可以注册,所以应用程序和谷歌项目之间的连接是可能的。已设置并启用SHA-1指纹、权限和API
可以向AccountApi请求电子邮件,但不能向PeopleApi请求。有人能帮我吗?我尝试了几种“解决方案”,但都不起作用,这个空的PeopleApi你的测试设备上有帐户吗?你的logcat返回值是多少?请点击此链接是的,我的测试设备是我的手机@IntelliJAmiya没有特殊的logcat返回值,我要看看这个link@IntelliJAmiya嗯,看起来这正是我正在做的,但它不起作用:(我会再看一次指纹,也许那里出了问题,但我不这么认为