1
votes

I have method who creates the contact and sends the request. After call Execute() method, an excepted appears. How to correctly send changes in Google contacts?

private readonly PeopleServiceService _peopleService;
private readonly string[] _scopes = { PeopleServiceService.Scope.Contacts };

UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                secrets,
                _scopes,
                userName,
                CancellationToken.None).Result;

_peopleService = new PeopleServiceService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = "ApplicationName",
            });

var contactToCreate = new Person
            {
                Names = new List<Name>
                {
                    new Name
                    {
                        DisplayName = "John"
                    }
                },
                PhoneNumbers = new List<PhoneNumber>
                {
                    new PhoneNumber
                    {
                        Value = "+7 777 777 7777"
                    }
                }
            };

var request = new PeopleResource.CreateContactRequest(_peopleService, contactToCreate);
request.Execute(); // Exception here

That exception: enter image description here

1
Any chance that you have changed your scopes without authenticating the user?DaImTo

1 Answers

1
votes

insufficient authentication scopes.

Means that you dont currently have the permission to do what you are trying to do.

Method: people.createContact requires the following scope of permissions in order to exicute.

https://www.googleapis.com/auth/contacts

You apear to be using that. So one of two things is happening here.

  1. You have changed the scope in your code and failed to logout and reauthenticate the script in order to get the new permissions.
  2. there is some bug in the api. I have tested it and the API appears to be working.

Double check your code make sure your using that Scope then try and login again.