Search code examples
c#google-api-dotnet-clientgoogle-shared-contacts

Google Contacts API with Service Account issue


So, I've basically got this working, except for one issue. I've got a google service account set up so it can access our domain contacts. And it can batch query them perfectly!

But if I call cr.Retrieve("some-contact-url-here"), it throws an error griping about not having a Refresh token. I'm using a service account though, so I don't get a refresh token when I authenticate.

And I can't seem to find any good answer as to how I'm supposed to get a refresh token for a service account. There's one or two stackoverflow posts which actively mention getting a refresh token with a service account....but what they linked to has since been redirected. Anything else I've found to do with refresh tokens has basically been about authenticating manually and storing the token. Because I need to use a Service Account, that is not a possibility.


Solution

  • Ok, based on several hours of bashing my head violently against the API, it looks like there's basically no way to get a refresh token when you're authenticating as a Service Account. Expected behavior, really.

    Anyway, to get around the issue, you can load all of the contacts into memory,

    feed.AutoPaging = true;
    foreach (var c in feed.Entries)
    {
        contactList.Add(c);
    }
    

    And you can update|delete|etc then. Grossly inefficient though. Especially if your contact list gets rather big.