I\'m beating myself bloody trying to get a simple service acccount login to work in C#, to Google API and Google Analytics. My company is already getting data into Analytics, an
The invalid credentials error is happening because the scopes you specified aren't actually getting sent with your credentials. I made the same mistake and only realized after I debugged and still saw 0 scopes on the credential after the CreateScoped call.
A GoogleCredential is immutable so CreateScoped creates a new instance with the specified scopes set.
Reassign your credentials variable with the scoped result like so and it should work:
if (_cred.IsCreateScopedRequired) {
_cred = _cred.CreateScoped(AnalyticsService.Scope.Analytics);
}
The accepted answer works because it's achieving the same thing in a more difficult way.