C# google 人 api,peopleRequest 缺少 PersonFields 属性
C# google people api, peopleRequest missing PersonFields attribute
我正在努力学习 google 人 api 以开发应用程序。
我正在使用 google api 教程
https://developers.google.com/people/v1/getting-started
using Google;
using Google.Apis.Auth.OAuth2;
using Google.Apis.People.v1;
using Google.Apis.People.v1.Data;
using Google.Apis.Services;
...
static void Main(string[] args)
{
// Create OAuth credential.
UserCredential credential =
GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = "CLIENT_ID",
ClientSecret = "CLIENT_SECRET"
},
new[] { "profile",
"https://www.googleapis.com/auth/contacts.readonly" },
"me",
CancellationToken.None).Result;
// Create the service.
var peopleService = new PeopleService (new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "APP_NAME",
});
PeopleResource.ConnectionsResource.ListRequest peopleRequest =
peopleService.People.Connections.List("people/me");
peopleRequest.PersonFields = "names,emailAddresses";
ListConnectionsResponse connectionsResponse = peopleRequest.Execute();
IList<Person> connections = connectionsResponse.Connections;
当我使用教程中的示例脚本时,信息检索正常。
我使用 C# 在 visual studio 中创建了一个灵魂。
我添加了对所有需要的 google api 的引用。
项目无法编译,因为无法识别 PersonFields。
此属性是成功操作所必需的
所以,我遇到了同样的问题,经过数小时的脑筋急转弯试图解决它,我找到了接近解决方案的东西。
peopleRequest.RequestMaskIncludeField
具有这样的值:
peopleRequest.RequestMaskIncludeField = "person.names";
("names" 单独不行,"person.names" 行)
有了这个我设法没有编译错误和答案,唯一让我很痛苦的是根据文档,这已被弃用...
希望google尽快更新API,希望对您有所帮助!!
我运行陷入同样的问题。经过几个小时的尝试,我发现 NOT 可以使用 People.v1
命名空间(就像您在代码示例中所做的那样),而是使用 PeopleService.v1
命名空间。这不是 Google 文档明确说明的内容(它根本没有说明),目前我不太确定这些不同名称空间背后的原因是什么。很想找到一些说明......
这是我的源泉和工作。
peopleRequest.RequestMaskIncludeField = new List<string>() {
"person.phoneNumbers" ,
"person.EmailAddresses",
"person.names"
};
ListConnectionsResponse people = peopleRequest.Execute();
if (people != null && people.Connections != null && people.Connections.Count > 0)
{
foreach (var person in people.Connections)
{
Console.Write(person.Names != null ? (person.Names[0].DisplayName + " " ?? "n/a") : "n/a ");
Console.Write(person.EmailAddresses?.FirstOrDefault()?.Value + " ");
Console.WriteLine(person.PhoneNumbers?.FirstOrDefault()?.Value);
}
if (people.NextPageToken != null)
{
GetPeople(service, people.NextPageToken);
}
我正在努力学习 google 人 api 以开发应用程序。
我正在使用 google api 教程 https://developers.google.com/people/v1/getting-started
using Google;
using Google.Apis.Auth.OAuth2;
using Google.Apis.People.v1;
using Google.Apis.People.v1.Data;
using Google.Apis.Services;
...
static void Main(string[] args)
{
// Create OAuth credential.
UserCredential credential =
GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = "CLIENT_ID",
ClientSecret = "CLIENT_SECRET"
},
new[] { "profile",
"https://www.googleapis.com/auth/contacts.readonly" },
"me",
CancellationToken.None).Result;
// Create the service.
var peopleService = new PeopleService (new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "APP_NAME",
});
PeopleResource.ConnectionsResource.ListRequest peopleRequest =
peopleService.People.Connections.List("people/me");
peopleRequest.PersonFields = "names,emailAddresses";
ListConnectionsResponse connectionsResponse = peopleRequest.Execute();
IList<Person> connections = connectionsResponse.Connections;
当我使用教程中的示例脚本时,信息检索正常。
我使用 C# 在 visual studio 中创建了一个灵魂。 我添加了对所有需要的 google api 的引用。
项目无法编译,因为无法识别 PersonFields。 此属性是成功操作所必需的
所以,我遇到了同样的问题,经过数小时的脑筋急转弯试图解决它,我找到了接近解决方案的东西。
peopleRequest.RequestMaskIncludeField
具有这样的值:
peopleRequest.RequestMaskIncludeField = "person.names";
("names" 单独不行,"person.names" 行)
有了这个我设法没有编译错误和答案,唯一让我很痛苦的是根据文档,这已被弃用...
希望google尽快更新API,希望对您有所帮助!!
我运行陷入同样的问题。经过几个小时的尝试,我发现 NOT 可以使用 People.v1
命名空间(就像您在代码示例中所做的那样),而是使用 PeopleService.v1
命名空间。这不是 Google 文档明确说明的内容(它根本没有说明),目前我不太确定这些不同名称空间背后的原因是什么。很想找到一些说明......
这是我的源泉和工作。
peopleRequest.RequestMaskIncludeField = new List<string>() {
"person.phoneNumbers" ,
"person.EmailAddresses",
"person.names"
};
ListConnectionsResponse people = peopleRequest.Execute();
if (people != null && people.Connections != null && people.Connections.Count > 0)
{
foreach (var person in people.Connections)
{
Console.Write(person.Names != null ? (person.Names[0].DisplayName + " " ?? "n/a") : "n/a ");
Console.Write(person.EmailAddresses?.FirstOrDefault()?.Value + " ");
Console.WriteLine(person.PhoneNumbers?.FirstOrDefault()?.Value);
}
if (people.NextPageToken != null)
{
GetPeople(service, people.NextPageToken);
}