gpt4 book ai didi

android - Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) 返回 null

转载 作者:搜寻专家 更新时间:2023-11-01 08:41:51 24 4
gpt4 key购买 nike

我尝试了所有方法,但仍然无法解决这个问题,Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) 总是返回 null。

这是我的代码:

mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API, Plus.PlusOptions.builder().build())
.addScope(Plus.SCOPE_PLUS_LOGIN)
.addScope(Plus.SCOPE_PLUS_PROFILE)
.build();

这是onConnected():

@Override
public void onConnected(Bundle arg0) {
mSignInClicked = false;
Toast.makeText(this, "User is connected!", Toast.LENGTH_LONG).show();

// Get user's information
if (login_status == 1) {
mSignInClicked = false;
login_status = 0;
/* This Line is the key */
Plus.PeopleApi.loadVisible(mGoogleApiClient, null).setResultCallback(LoginFragment.this);

getProfileInformation();
} else {
signOutFromGplus();
}

}

这是 getProfileInformation()::::/** * 获取用户的信息名称、电子邮件、个人资料照片 */'

private void getProfileInformation() {
try {
String emailAddr = Plus.AccountApi.getAccountName(mGoogleApiClient);
Toast.makeText(this,
"Person information is GOT:" + emailAddr, Toast.LENGTH_LONG).show();

Person signedInUser = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
Toast.makeText(this,
"Person information obj:" + signedInUser, Toast.LENGTH_LONG).show();

if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
Person currentPerson = Plus.PeopleApi
.getCurrentPerson(mGoogleApiClient);
String personName = currentPerson.getDisplayName();
String personPhotoUrl = currentPerson.getImage().getUrl();
String personGooglePlusProfile = currentPerson.getUrl();
String email = Plus.AccountApi.getAccountName(mGoogleApiClient);

Log.e("", "Name: " + personName + ", plusProfile: "
+ personGooglePlusProfile + ", email: " + email
+ ", Image: " + personPhotoUrl);
Toast.makeText(this,
"Person information is GOT:" + email, Toast.LENGTH_LONG).show();

// by default the profile url gives 50x50 px image only
// we can replace the value with whatever dimension we want by
// replacing sz=X

} else {

signOutFromGplus();
Toast.makeText(this,
"Person information is null", Toast.LENGTH_LONG).show();
}
dialog_google.dismiss();
;
} catch (Exception e) {
e.printStackTrace();
}
}

我的 Android list 。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="learn.english.from.hinkhoj" >

<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

<activity
android:name=".activity.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activity.LoginFragment"
android:label="@string/title_activity_login_fragment" >
</activity>
</application>

</manifest>

最佳答案

1) 尝试将以下简单代码添加到您的回调中:

@Override
public void onConnected(Bundle bundle) {
Person me = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
if (me != null) {
Person.Name name = me.getName();
String given = name.getGivenName();
String family = name.getFamilyName();

Log.d(TAG, "Given: " + given + ", Family: " + family);
}
}

2) 添加两个 SHA1 签名到Google Developers Console / Credentials - 一个从您的真实 keystore 中提取,另一个用于 ~/.android/debug.keystore(在 Mac 和 Linux 上;在 Windows 上搜索类似路径):

keytool -exportcert -keystore ~/.android/debug.keystore -list -v

3) 在 Google Developers Console / APIs 中启用“Google+ API”和“Google Play Android Developer API” :

console

4) 在调试之前运行命令:

adb shell setprop log.tag.GooglePlusPlatform VERBOSE
adb logcat

5) 如果没有任何帮助 - 请等待几个小时。昨天晚上我遇到了一个应用程序问题(Plus.PeopleApi.getCurrentPerson() 无论我尝试什么都返回 null)。今天早上,谷歌的爪牙已经修复了它。

关于android - Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31850720/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com