Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8210467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:04:47+00:00 2026-06-07T10:04:47+00:00

I have a .NET application that is using Google Drive to access the user’s

  • 0

I have a .NET application that is using Google Drive to access the user’s file. I am able to get the authorization code, and I have been able to exchange the authorization code by the AccessToken and the RefreshToken. The issue is that I cannot refresh the access token, and it expires after an hour.

Similar to this question: How to generate access token using refresh token through google drive API? except that I am working in .NET (using the Google.APIs… DLLs).

I am aware of this: https://developers.google.com/accounts/docs/OAuth2InstalledApp#refresh however, I am expecting some sort of method available in the IAuthorizationState or OAuth2Authenticator object to allow me refresh the access token.

Please advise. Thanks.

Please note that using this code I am able to get the Access Token. It is just that I am expecting this code to be inside the Google API.

    public class OAuth2AccessTokenReponse
    {
        public string access_token;
        public int expires_in;
        public string token_type; 
    }
    public static string refreshAccessToken()
    {
        using (System.Net.WebClient client = new System.Net.WebClient())
        {
            byte[] response = client.UploadValues("https://accounts.google.com/o/oauth2/token", new System.Collections.Specialized.NameValueCollection(){
                {"client_id", ClientID},
                {"client_secret", ClientSecret},
                {"refresh_token", "XXXXX"},
                {"grant_type", "refresh_token"}
            });
            string sresponse = System.Text.Encoding.Default.GetString(response);
            OAuth2AccessTokenReponse o = (OAuth2AccessTokenReponse) Newtonsoft.Json.JsonConvert.DeserializeObject(sresponse, typeof(OAuth2AccessTokenReponse));
            return o.access_token;        
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T10:04:48+00:00Added an answer on June 7, 2026 at 10:04 am

    I studied a more suitable sample: the Tasks.WinForms.NoteMgr of the GoogleApisSample… and with it I found the solution.

    The solution is in the code below. The key part of it is calling arg.RefreshToken(state);

    Thanks.

        public static Authentication.IAuthenticator UseSavedAuthorization()
        {          
    
            var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description);
            provider.ClientIdentifier = ClientID;
            provider.ClientSecret = ClientSecret;
    
            OAuth2Authenticator<NativeApplicationClient> auth = new OAuth2Authenticator<NativeApplicationClient>(provider, getState);
    
            auth.LoadAccessToken();
    
            return auth;             
        }
    
    
    public static IAuthorizationState getState(NativeApplicationClient arg)
        {
            IAuthorizationState state = new AuthorizationState(new[] { TasksService.Scopes.Tasks.GetStringValue(), 
                    DriveService.Scopes.DriveFile.GetStringValue() , DriveService.Scopes.Drive.GetStringValue()
            });
            state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
    
            state.RefreshToken = "<refresh token previously saved>";        
            arg.RefreshToken(state); 
    
            return state; 
        }`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the core problem: I have a .NET application that is using COM interop
I have a small conundrum where I have an asp.net application that's using forms
I have an asp.net mvc2 application that is using StructureMap 2.6 and NHibernate 3.x.
I have an ASP.NET web application that is using forms authentication. Everything is configured
I have an ASP.net web service that I'm using for a web application which
I currently have an application I'm writing in c# (using .NET) that requires me
I have a c# windows application that can successfully record audio using user's desktop
Background I am currently implementing an application with Google Drive/Docs. Using the latest .NET
I am using Google Data API for .Net(version 1.9) in my application. I have
I have .NET application that is hosted on IIS 6.1 It is impossible to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.