我正在使用新的Google People API将用户的Google联系人列表加载到我的应用中。这是我的一些课程-正如我所说的,它直接来自在线指南,并且效果很好。但是,我找不到任何类似的代码来加载联系人组列表(例如,家人,同事等)。在使用Contacts API之前,我已经完成了这项工作,并且有很多示例代码,但是找不到People API的任何示例代码。 如果这个问题仍然太笼统,请提出建议,让我更加具体。谢谢。
using Google.Apis.Auth.OAuth2;
using Google.Apis.People.v1.Data;
using Google.Apis.People.v1;
using Google.Apis.Services;
public class GoogleContacts
{
private String m_client_secret = ".....";
private String m_client_id = "......apps.googleusercontent.com";
public GoogleContacts()
{
// Create OAuth credential.
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = m_client_id,
ClientSecret = m_client_secret
},
new[] { "profile", "https://www.googleapis.com/auth/contacts.readonly" },
"me",
CancellationToken.None).Result;
// Create the service.
var service = new PeopleService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "MyApp",
});
PeopleResource.ConnectionsResource.ListRequest peopleRequest =
service.People.Connections.List("people/me");
peopleRequest.RequestMaskIncludeField = new List<string>() {
"person.addresses",
"person.names" };
peopleRequest.SortOrder = (PeopleResource.ConnectionsResource.ListRequest.SortOrderEnum) 1;
ListConnectionsResponse people = peopleRequest.Execute();
if (people != null && people.Connections != null && people.Connections.Count > 0)
{
foreach (var person in people.Connections)
{ //do stuff with people
// etc...
答案 0 :(得分:1)
我最终找到了一种方法。请注意,它使用的是PeopleService.v1,而不是People.v1。这是一个显示组列表然后显示联系人列表的类:
cmd /c `" "C:\Program Files (x86)\National Instruments\LabVIEW 2018\LabVIEW.exe" $runner_File > $runnerResult_File `"