Google.GoogleApiException: 'Google.Apis.Requests.RequestError Request had insufficient authentication scopes

Viewed 257

I'm trying to create a google contact using Google People API and C#. I'm able to list the contact . But crating contact gives me this exception

Google.GoogleApiException: 'Google.Apis.Requests.RequestError
Request had insufficient authentication scopes. [403]
Errors [
    Message[Insufficient Permission] Location[ - ] Reason[insufficientPermissions] Domain[global]

Fallowing is the code for the method

public static void CreateContact()
    {
    string m_client_secret = "LIsZiU972ThMyD7.....";
    string m_client_id = "....n3vgb1o235m.apps.googleusercontent.com";

    UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
            new ClientSecrets
            {
                ClientId = m_client_id,
                ClientSecret = m_client_secret
            },
            new[] { "profile", "https://www.googleapis.com/auth/contacts" },
            "me",
            CancellationToken.None).Result;

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

        var contactToCreate = new Person();
        var names = new List<Name> { new Name() { GivenName = "Jhon", FamilyName = "Doe" } };
        contactToCreate.Names = names;             

        var request = new PeopleResource.CreateContactRequest(service, contactToCreate);
        var createdContact = request.Execute();
}

For me It looks like some issue in the scope new[] { "profile", "https://www.googleapis.com/auth/contacts" }. Tried multiple scopes but no luck. Anyone has a clue?

0 Answers
Related