I have a question about how correctly add a contact to Google Contacts using Google API. For authorization I use external Json file Generated. When I execute it , it doesn't give any mistakes but No Contact is Added to Google Contacts. What can be wrong with the code? Please find code below
Thanks
private async Task Run()
{
GoogleCredential credential;
using (Stream stream = new FileStream(@"D:\project1.json", FileMode.Open, FileAccess.Read, FileShare.Read))
{
credential = GoogleCredential.FromStream(stream);
}
string[] scopes = new string[] {
PeopleServiceService.Scope.Contacts,
PeopleServiceService.Scope.ContactsReadonly,
PeopleServiceService.Scope.ContactsOtherReadonly,
};
credential = credential.CreateScoped(scopes);
BaseClientService.Initializer initializer = new BaseClientService.Initializer()
{
HttpClientInitializer = (IConfigurableHttpClientInitializer)credential,
ApplicationName = "Project1",
GZipEnabled = true,
};
PeopleServiceService service = new PeopleServiceService(initializer);
Person contactToCreate = new Person();
List<Name> names = new List<Name>();
names.Add(new Name() { GivenName = "Alex", FamilyName = "Breen", DisplayName = "Alex Breen" });
contactToCreate.Names = names;
List<PhoneNumber> phoneNumbers = new List<PhoneNumber>();
phoneNumbers.Add(new PhoneNumber() { Value = "11-22-33" });
contactToCreate.PhoneNumbers = phoneNumbers;
List<EmailAddress> emailAddresses = new List<EmailAddress>();
emailAddresses.Add(new EmailAddress() { Value = "AlexBreen@mail.com" });
contactToCreate.EmailAddresses = emailAddresses;
PeopleResource.CreateContactRequest request = new PeopleResource.CreateContactRequest(service, contactToCreate);
Person createdContact = request.Execute();
Console.WriteLine(request);
}