How do I create a GoogleCredential from an authorized access_token?

Viewed 4313

I have an OAuth2 token like this...

{{
  "access_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "expires_in": "3600",
  "refresh_token": "xxxxxxxxxxxxxxxxxx",
  "token_type": "Bearer",
}}

and I'm trying to create a DriveService object...

Service = new DriveService(new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = "foo",
});

(like this?)

but I'm clearly not doing this properly and I'm having trouble finding documentation.

When I attempt to create a GoogleCredential to pass to the DriveService

GoogleCredential credential = GoogleCredential.FromJson(credentialAsSerializedJson).CreateScoped(GoogleDriveScope);

I get the following exception:

{System.InvalidOperationException: Error creating credential from JSON. Unrecognized credential type .

Am I going about this the wrong way entirely?

(This is the sample code context)

1 Answers
Related