axe
axe

Reputation: 2371

Google Drive simple API Access authorization fail

I'm trying to authorize in google using .NET SDK provided, but it failes with "Invalid credentials" error. I found this answer

Google Calendar V3 2 Legged authentication fails

but I still don't see where is the mistake. Looks like everything is done as described.

Here is my code

const string CONSUMER_KEY = "mytestdomain.com";
const string CONSUMER_SECRET = "my_consumer_secret";
const string TARGET_USER = "user";
const string SERVICE_KEY = "some_api_key";

var auth = new OAuth2LeggedAuthenticator(CONSUMER_KEY, CONSUMER_SECRET, TARGET_USER, CONSUMER_KEY);

var service = new DriveService(auth) { Key = SERVICE_KEY };
var results = service.Files.List().Fetch();

Console.WriteLine(results.Items.Count);

and here are screenshots from google control panel. I just replaced domain name, consumer key and api key.

Screenshot from Manage API client access page Screenshot from "Manage API client access" page

Screenshot from Manage OAuth key and secret for this domain page Screenshot from "Manage OAuth key and secret for this domain" page

Screenshot from API Access page in Google API console Screenshot from "API Access" page in "Google API console"

Upvotes: 2

Views: 1340

Answers (1)

Nicolas Garnier
Nicolas Garnier

Reputation: 12384

OAuth 1.0 has been deprecated and 2-Legged OAuth 1.0 with it. Although it is still supported for the deprecation period if I were you I would use Service Accounts with OAuth 2.0 to perform domain-wide delegation of authority.

This is very well documented on the Perform Google Apps Domain-wide Delegation of Authority page of the Google Drive SDK documentation.

Upvotes: 1

Related Questions