How to create a instance of UserCredential if I already have the value of Access Token?

Assuming you already have the tokens you can do the following string[] scopes = new string[] { PlusService.Scope.PlusLogin, PlusService.Scope.UserinfoEmail, PlusService.Scope.UserinfoProfile }; var flow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer { ClientSecrets = new ClientSecrets { ClientId = “xxx.apps.googleusercontent.com”, ClientSecret = “xxxx” }, Scopes = scopes, DataStore = new FileDataStore(“Store”) }); var token = new TokenResponse { AccessToken … Read more

Google API OAuth2, Service Account, “error” : “invalid_grant”

After some investigations I found, that Google API does not work as expected with your personal account @gmail.com. You should have organization domain account in Google in format you@your_organisation_domain Then, what is also pretty confusing, there is documentation at Google Drive API page, with “Delegate domain-wide authority to your service account” section not mentioned at … Read more

How to programmatically remove a file from “share with me” in Google drive

The problem is that the user in question doesn’t own the file. After a lot of digging I realised that what you want to do is to remove the permissions for the user on the file in question. The first thing you need to do is run an about.get on the current user: return service.About.Get().Execute(); … Read more

GoogleWebAuthorizationBroker.AuthorizeAsync Hangs

Found a way to get passed this. I used GoogleAuthorizationCodeFlow instead. this is what it turned out to look like: ClientSecrets secrets = new ClientSecrets() { ClientId = CLIENT_ID, ClientSecret = CLIENT_SECRET }; var token = new TokenResponse { RefreshToken = REFRESH_TOKEN }; var credentials = new UserCredential(new GoogleAuthorizationCodeFlow( new GoogleAuthorizationCodeFlow.Initializer { ClientSecrets = secrets … Read more

Accessing Google Spreadsheets with C# using Google Data API

According to the .NET user guide: Download the .NET client library: Add these using statements: using Google.GData.Client; using Google.GData.Extensions; using Google.GData.Spreadsheets; Authenticate: SpreadsheetsService myService = new SpreadsheetsService(“exampleCo-exampleApp-1”); myService.setUserCredentials(“[email protected]”, “mypassword”); Get a list of spreadsheets: SpreadsheetQuery query = new SpreadsheetQuery(); SpreadsheetFeed feed = myService.Query(query); Console.WriteLine(“Your spreadsheets: “); foreach (SpreadsheetEntry entry in feed.Entries) { Console.WriteLine(entry.Title.Text); } Given … Read more

How Google API V 3.0 .Net library and Google OAuth2 Handling refresh token

Spent the last two days figuring this out myself. The library does not refresh the tokens automatically unless you specify “access_type=offline”. https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth I’m gonna paste the code I’m using and if there is anything you don’t understand, just ask. I have read so many posts and I litteraly got this working right now so there … Read more

Could not load file or assembly System.Net.Http.Primitives. Located assembly’s manifest definition does not match the assembly reference

I ran into the same issue with the Google API’s. The main issue here is if you install the Microsoft Http Client Libraries it puts in your project an updated version of the System.Net.Http.Primitives DLL. The web.config assumes you are still using the default version of 1.5. There are two things that need to happen … Read more