gpt4 book ai didi

Android Google People API 连接始终为空

转载 作者:行者123 更新时间:2023-11-29 19:30:29 25 4
gpt4 key购买 nike

我正在尝试运行 Google People API sample code按照以下步骤 here .不幸的是,它总是从 ListConnectionsResponse 的 response.getConnections() 获得空连接。下面AsyncTask在登录成功后在onActivityResult中执行:

class PeoplesAsync extends AsyncTask<String, Void, List<String>> {


@Override
protected void onPreExecute() {
super.onPreExecute();
updateUI();
}

@Override
protected List<String> doInBackground(String... params) {

List<String> nameList = new ArrayList<>();

try {
People peopleService = PeopleHelper.setUp(MainActivity.this, params[0]);

ListConnectionsResponse response = peopleService.people().connections()
.list("people/me").setRequestMaskIncludeField("person.names,person.emailAddresses,person.phoneNumbers")
.execute();
List<Person> connections = response.getConnections();

//error: connections is always null
for (Person person : connections) {
if (!person.isEmpty()) {
List<Name> names = person.getNames();
List<EmailAddress> emailAddresses = person.getEmailAddresses();
List<PhoneNumber> phoneNumbers = person.getPhoneNumbers();

if (phoneNumbers != null)
for (PhoneNumber phoneNumber : phoneNumbers)
Log.d(TAG, "phone: " + phoneNumber.getValue());

if (emailAddresses != null)
for (EmailAddress emailAddress : emailAddresses)
Log.d(TAG, "email: " + emailAddress.getValue());

if (names != null)
for (Name name : names)
nameList.add(name.getDisplayName());

}
}

} catch (IOException e) {
e.printStackTrace();
}

return nameList;
}


@Override
protected void onPostExecute(List<String> nameList) {
super.onPostExecute(nameList);

progressBar.setVisibility(View.GONE);

recyclerView.setVisibility(View.VISIBLE);

adapter = new PeopleAdapter(nameList);
recyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.this));
recyclerView.setAdapter(adapter);

}
}

在 Google People API 中导致空响应连接的原因是什么以及如何解决?

最佳答案

真是误会,ListConnectionsResponse response = peopleService.people().connections() .list("people/me") 不是针对用户的个人资料,而是针对用户连接的个人资料。如果您需要用户的个人资料信息:

Person profile = peopleService.people().get("people/me").execute();

if (!profile.isEmpty()) {

List<Name> names = profile.getNames();
List<Birthday> birthdays = profile.getBirthdays();
List<Gender> genders = profile.getGenders();
List<Url> urls = profile.getUrls();
List<EmailAddress> emailAddresses = profile.getEmailAddresses();
List<Photo> profileImages = profile.getPhotos();

String displayName = names.get(0).getDisplayName();
String birthday = birthdays.get(0).getText();
String gender = genders.get(0).getValue();
String email = emailAddresses.get(0).getValue();
String profileImage = profileImages.get(0).getUrl();

}

关于Android Google People API 连接始终为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40039563/

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