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 8552727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:29:22+00:00 2026-06-11T14:29:22+00:00

I am currently trying to add functionality to our company’s ASP.NET website which will

  • 0

I am currently trying to add functionality to our company’s ASP.NET website which will allow end users to upload files generated from the website into their own Google Drive (within the same company).

The company has it’s own Google Domain which includes Mail, Drive, Contacts, Calendar (and pretty much everything else). It uses SAML to authenticate with our Active Directory set up which links in to Google.

It should be noted that this code works OK with my @gmail.com account. With the companies Google App Domain account, I get the invalid credentials error (shown at the bottom). I have spoken with our Google Admin who claims that I have no restrictions on my account with regards to Drive API access. Please also bear in mind that the API ID/Secret’s were created with my company account rather than a Gmail account.

using System;
using System.IO;
using System.Text;
using System.Web;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OAuth2;
using Google.Apis.Authentication.OAuth2;
using Google.Apis.Drive.v2;
using Google.Apis.Util;

namespace GoogleTesting
{
    public partial class GoogleAuth : System.Web.UI.Page
    {
        private static readonly string CLIENTID = "xxxxxxxxx.apps.googleusercontent.com";
        private static readonly string CLIENTSECRET = "xxxxxxxxxxxxxxxxxxxxxx";
        private static readonly string APIKEY = "xxxxxxxxxxx";
        private static readonly string REDIRECTURI =  http://localhost:61111/default.aspx";
        private static readonly string[] SCOPES = new[] { DriveService.Scopes.Drive.GetStringValue() };

        private static DriveService driveService;
        private static OAuth2Authenticator<WebServerClient> authenticator;
        private static IAuthorizationState _state;

        private IAuthorizationState AuthState
        {
            get
            {
                return _state ?? HttpContext.Current.Session["GoogleAuthState"] as IAuthorizationState;
            }
        }

        private OAuth2Authenticator<WebServerClient> CreateAuthenticator()
        {
            var provider = new WebServerClient(GoogleAuthenticationServer.Description, CLIENTID, CLIENTSECRET);
            var authenticator = new OAuth2Authenticator<WebServerClient>(provider, GetAuthorization);
            return authenticator;
        }

        private IAuthorizationState GetAuthorization(WebServerClient client)
        {
            IAuthorizationState state = AuthState;
            if (state != null)
            {
                if (state.AccessTokenExpirationUtc.Value.CompareTo(DateTime.Now.ToUniversalTime()) > 0)
                    return state;
                else
                    state = null;
            }
            state = client.ProcessUserAuthorization(new HttpRequestInfo(HttpContext.Current.Request));
            if (state != null && (!string.IsNullOrEmpty(state.AccessToken) || !string.IsNullOrEmpty(state.RefreshToken)))
            {
                if (state.RefreshToken == null)
                    state.RefreshToken = "";
                HttpContext.Current.Session["GoogleAuthState"] = _state = state;
                return state;
            }
            client.RequestUserAuthorization(SCOPES, "", HttpContext.Current.Request.Url);
            return null;
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if(authenticator == null)
                authenticator = CreateAuthenticator();

            if (driveService == null)
            {
                driveService = new DriveService(authenticator);
                driveService.Key = APIKEY;
            }
            //We should now be authenticated and ready to use Drive API.
            UploadFile();
        }

        private void UploadFile()
        {
            Google.Apis.Drive.v2.Data.File newFile = new Google.Apis.Drive.v2.Data.File { Title = "Test File", MimeType = "text/plain" };
            byte[] byteArray = Encoding.ASCII.GetBytes("Body of the document.");
            MemoryStream stream = new MemoryStream(byteArray);
            FilesResource.InsertMediaUpload request = driveService.Files.Insert(newFile, stream, newFile.MimeType);
            request.Convert = true;
            request.Upload(); 
        }
    }
}

The problem occurs on the “request.Upload” line with the following exception.

Exception Details: System.Exception: Invalid Credentials

Source Error: Line 85: request.Upload();

Source File: C:\TMGGoogle\TMGGoogle\TMGGoogle\GoogleAuth.aspx.cs
Line: 85

Stack Trace:

[Exception: Invalid Credentials]
Google.Apis.Upload.ResumableUpload`1.Upload() +722
GoogleTesting.GoogleAuth.UploadFile()

Any help is much appreciated. Thanks.

  • 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-11T14:29:23+00:00Added an answer on June 11, 2026 at 2:29 pm

    Well, I figured out the root cause of the problem. It turns out that our company’s Google Apps account had Docs API access turned off.

    Our Google Apps Administrator has since turned it on and this has resolved the issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to add an MSChart to a partial view in ASP.NET MVC
I'm currently trying to add some testing functionality into our builds, and in order
I am trying to create a login form on my ASP.NET website. Currently, there's
I'm currently trying to implement a simple Add-In for InfoPath 2010 Filler/Editor mode, which
I'm trying to add simple Authentication and Authorization to an ASP.NET MVC application. I'm
I am currently trying to implement an Add functionality to my page. Currently, the
Good evening guys, I'm currently trying to add the visualization functionality of d3 to
I'm working on a few ASP.NET MVC projects which all require database functionality. Unfortunately,
Currently trying at add ajax to a site, after much reading I discovered that
I'm currently trying to add PGP signing support to my small e-mail sending script

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.