我正在尝试使用以下代码获取Google plus封面照片:
if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null)
{
Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
String personName = currentPerson.getDisplayName();
String userId = currentPerson.getId();
personPhotoUrl = currentPerson.getImage().getUrl();
String personGooglePlusProfile = currentPerson.getUrl();
boolean coverphoto = currentPerson.getCover().hasCoverPhoto();
String urlBackgroud = currentPerson.getCover().getCoverPhoto().getUrl();
String email = Plus.AccountApi.getAccountName(mGoogleApiClient);
Log.e("url","Background"+photo);
Log.e(TAG, "Name: " + personName + ", plusProfile: "
+ personGooglePlusProfile + ", email: " + email
+ ", Image: " + personPhotoUrl + ", userId: " + userId );
设置好封面照片后。我得到了带有URL的结果,但是没有设置封面照片,然后出现以下错误
07-28 18:18:39.952: W/System.err(9566): java.lang.NullPointerException
07-28 18:18:39.952: W/System.err(9566): at com.ylg.maps.MainActivity.getProfileInformation(MainActivity.java:224)
07-28 18:18:39.952: W/System.err(9566): at com.ylg.maps.MainActivity.onConnected(MainActivity.java:178)
07-28 18:18:39.952: W/System.err(9566): at com.google.android.gms.internal.hd.c(Unknown Source)
07-28 18:18:39.952: W/System.err(9566): at com.google.android.gms.common.api.c.eF(Unknown Source)
07-28 18:18:39.952: W/System.err(9566): at com.google.android.gms.common.api.c.d(Unknown Source)
07-28 18:18:39.952: W/System.err(9566): at com.google.android.gms.common.api.c$2.onConnected(Unknown Source)
07-28 18:18:39.952: W/System.err(9566): at com.google.android.gms.internal.hd.c(Unknown Source)
07-28 18:18:39.952: W/System.err(9566): at com.google.android.gms.internal.hd.ck(Unknown Source)
07-28 18:18:39.952: W/System.err(9566): at com.google.android.gms.internal.hc$h.b(Unknown Source)
07-28 18:18:39.952: W/System.err(9566): at com.google.android.gms.internal.hc$h.d(Unknown Source)
07-28 18:18:39.959: W/System.err(9566): at com.google.android.gms.internal.hc$b.fq(Unknown Source)
07-28 18:18:39.959: W/System.err(9566): at com.google.android.gms.internal.hc$a.handleMessage(Unknown Source)
07-28 18:18:39.959: W/System.err(9566): at android.os.Handler.dispatchMessage(Handler.java:99)
07-28 18:18:39.959: W/System.err(9566): at android.os.Looper.loop(Looper.java:137)
07-28 18:18:39.959: W/System.err(9566): at android.app.ActivityThread.main(ActivityThread.java:5103)
07-28 18:18:39.959: W/System.err(9566): at java.lang.reflect.Method.invokeNative(Native Method)
07-28 18:18:39.959: W/System.err(9566): at java.lang.reflect.Method.invoke(Method.java:525)
07-28 18:18:39.959: W/System.err(9566): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
07-28 18:18:39.959: W/System.err(9566): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-28 18:18:39.959: W/System.err(9566): at dalvik.system.NativeStart.main(Native Method)
然后我尝试了:
boolean coverphoto = currentPerson.getCover().hasCoverPhoto();
我仍然收到上述错误。如何解决用户未设置封面照片的问题?
谢谢!
最佳答案
当您的Google客户端已连接时,您需要拨打其他电话
如下 :
if (mGoogleApiClient.isConnected()) {
Plus.PeopleApi.load(mGoogleApiClient, person.getId())
.setResultCallback(new ResultCallback<People.LoadPeopleResult>() {
@Override
public void onResult(People.LoadPeopleResult loadPeopleResult) {
if (loadPeopleResult.getStatus().isSuccess()) {
PersonBuffer personBuffer = loadPeopleResult.getPersonBuffer();
if (personBuffer != null && personBuffer.getCount() > 0) {
Person currentUser = personBuffer.get(0);
personBuffer.release();
Person.Cover cover = currentUser.getCover();
if (cover != null) {
Person.Cover.CoverPhoto coverPhoto = cover.getCoverPhoto();
if (coverPhoto != null) {
String userCoverPhotoUrl = coverPhoto.getUrl();
Log.i("Main TAG", "Cover photo Url :" + userCoverPhotoUrl);
}
} else {
Log.i("TAG NO COVER", "Person has no cover");
}
}
}
}
});
}
关于android - Android中的Google Plus封面照片,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24995808/