1

I have an installed app that uses .NET and the Contacts API. I'm trying to convert to the People API. I'm having trouble getting started and finding a sample that shows how to use People API with the .NET library. For example, the samples listed under the Peoples API documentation doesn't include .NET. Where can I find a .NET sample for the People API?

Mark
  • 440
  • 4
  • 16
  • Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are [off-topic for Stack Overflow](https://stackoverflow.com/help/on-topic) nowadays, but the unaccepted answer to [.NET client for the Google People API](https://stackoverflow.com/questions/23759400/net-client-for-the-google-people-api) should lead you there. – Andrew Morton May 30 '21 at 14:28
  • 1
    You can file a [feature request](https://cloud.google.com/support/docs/issue-trackers) to ask to add C# documentation. – ziganotschka May 31 '21 at 07:36

1 Answers1

1

Start with this ;)

https://googleapis.dev/dotnet/Google.Apis.PeopleService.v1/latest/api/Google.Apis.PeopleService.v1.html

Get the nuget called Google.Apis.PeopleService.v1 https://github.com/googleapis/google-api-dotnet-client

Also, I'm sure you have seen this https://developers.google.com/people/v1/profiles It has some .net examples.

What exactly are you trying to accomplish? I am just about to complete converting an app that used contacts API to people API using a service account for the company.

ps. I can't copy the whole namespace in the answer hense answer with a link.

Edited: 20210608

        Person person = new Person();

        person.EmailAddresses = new List<EmailAddress>();
        person.EmailAddresses.Add(new EmailAddress() { Type = "work", Value = "sample@domain.com" });
        person.Names = new List<Name>();
        person.Names.Add(new Name() { FamilyName = "Lname2", GivenName = "Fname" });

        // link to peopleService code can be found in the comments
        // it's basically initializing PeopleServiceService with service account credentials
        Person retVal = peopleService.People.CreateContact(person).Execute();
Zunair
  • 1,085
  • 1
  • 13
  • 21
  • Thanks Zunair. Yes, I did see the namespace documentation. I was looking for some example .NET code that showed how to do some basic operations with contacts and groups. I'm figuring it out from the documentation, but I find some sample code very helpful, especially when getting started. I'm syncing a Windows address book to Google contacts. – Mark Jun 08 '21 at 18:45
  • 1
    see this for service initialization https://stackoverflow.com/questions/50385783/peopleapi-error-403-google-bugs-or-not/67878094#67878094 I'll add a small sample to create a user - I only use the Batch classes, use that if you plan to modify lots of data. – Zunair Jun 08 '21 at 22:17
  • 1
    here is the link to batch request code https://stackoverflow.com/questions/63598523/adding-users-from-directory-to-contacts/67877788#67877788 – Zunair Jun 08 '21 at 22:26
  • @Zunair, I tried to retrieve status of batch request, but seems like it is all null values. Have you tried reading Status property from PeopleResponse? – djacob Jun 10 '21 at 10:27
  • I just updated the batch request code - I didn't show how to execute the batch request :facepalm – Zunair Jun 30 '21 at 15:10
  • @djacob, and I actually didn't answer you - I haven't used PeopleResponse. Since it's a batch request, we need to use the batch response classes, such as BatchCreateContactsResponse from Google.Apis.PeopleService.v1.Data – Zunair Jun 30 '21 at 23:25