Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android google的People API与contacts API_Android_Android Contacts_Google Contacts Api_Google People - Fatal编程技术网

Android google的People API与contacts API

Android google的People API与contacts API,android,android-contacts,google-contacts-api,google-people,Android,Android Contacts,Google Contacts Api,Google People,在尝试使用用户的google帐户获取联系人时,我在使用people API后遇到了一些问题。它只返回所有列出的电子邮件地址中的几个。访问令牌和所有范围都已正确设置。 以下代码: People peopleService = new People.Builder(httpTransport, jsonFactory, credential) .build(); ListConnectionsResponse response = peopleService.

在尝试使用用户的google帐户获取联系人时,我在使用people API后遇到了一些问题。它只返回所有列出的电子邮件地址中的几个。访问令牌和所有范围都已正确设置。 以下代码:

People peopleService = new People.Builder(httpTransport, jsonFactory, credential)
                    .build();
ListConnectionsResponse response = peopleService.people().connections().list("people/me")
                    .setPageSize(500).setSortOrder("FIRST_NAME_ASCENDING")
                    .setAccessToken(tokenResponse.getAccessToken())
                    .setAlt("json")
                    .setRequestMaskIncludeField("person.names,person.emailAddresses,person.phoneNumbers")
                    . execute();
   connections = response.getConnections();
相反,如果我使用谷歌的联系人API,那么我收到的电子邮件地址数量将超过人们。联系人API代码:

URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/default/full");
    ContactFeed resultFeed = myService.getFeed(feedUrl, ContactFeed.class);

    // Print the results
    System.out.println(resultFeed.getTitle().getPlainText());
    for (ContactEntry entry : resultFeed.getEntries()) {
          ....
          .....
          .......
 }

我想知道他们之间是否有任何区别,我必须使用哪一个更好的结果,或者我遗漏了什么。请建议。谢谢

People API是最新的。通读一遍,People API简化了对Google+API和Contacts API的单独调用。现在你只需要使用一个

“new People API使用了最新的协议和技术 最终将取代使用GData的Contacts API 协议”

获取用户的时,请确保在使用时指定

https://www.googleapis.com/auth/contacts
-请求为您的应用程序提供对已验证用户的Google contacts中联系人的读写访问权限。
https://www.googleapis.com/auth/contacts.readonly
-请求为您的应用程序授予对已验证用户的Google contacts中联系人的读取权限


在People API和Contacts API之间检查此项。

我不确定java代码是否存在任何问题,但如果您查看发送的请求,应该是这样的:

网址:

我能够用正确的电子邮件和姓名获得所有联系人。如果你用谷歌“管理谷歌联系人”,你会看到一个联系人列表。从那里得到那个数字,然后打印出应该匹配的连接计数。您只需要确保页面大小足够大,或者您必须处理分页以获取所有联系人

我还意识到requestMask.includeField对您放置的参数和空间非常敏感。“person.name,person.email\u地址”有效,“person.name,person.email\u地址”无效


使用旧的contact api,您可以查询q参数,我认为people api不提供这种功能。我认为通过关键字筛选搜索的功能对于减少请求大小非常重要。

我已正确添加了所有范围,但people api提供的联系人电子邮件地址数量不如contacts api。check out为您提供了受支持的模式和方法。