Issues with Google OAuth 2.0 - Try to implement Google Spreadsheets API version 3.0 on website

Posted on 2014-08-06
Last Modified: 2016-06-21
Hi guys, really need some help and advice here. I am planning to create a website that can read the data on my google sheets (private) and pull data from there to be shown on my website.

I created a new visual studio solution  for and c# and tried the first part of the codes on my page called WebForm1.

I followed everything on this page: -> Google Spreadsheets API version 3.0.

So i am trying out the first part, trying to get authenticated. Using OAuth 2.0.

I placed the CLIENT_ID, CLIENT_SECRET and REDIRECT_URI as per generated from I have removed it for now.

However i am facing an error. This is the Error message i receive: error-value-cannot-be-null-para-name-acc
This is the code on my WebForm1.aspx.cs Page:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Google.GData.Client;
using Google.GData.Spreadsheets;

namespace i555
    public partial class WebForm1 : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)


        protected void Button1_Click(object sender, EventArgs e)
            // STEP 1: Configure how to perform OAuth 2.0

            // TODO: Update the following information with that obtained from
            // After registering
            // your application, these will be provided for you.

            string CLIENT_ID = "[REMOVE_FOR_NOW]";

            // This is the OAuth 2.0 Client Secret retrieved
            // above.  Be sure to store this value securely.  Leaking this
            // value would enable others to act on behalf of your application!
            string CLIENT_SECRET = "[REMOVE_FOR_NOW]";

            // Space separated list of scopes for which to request access.
            string SCOPE = "";

            // This is the Redirect URI for installed applications.
            // If you are building a web application, you have to set your
            // Redirect URI at
            string REDIRECT_URI = "[REMOVE_FOR_NOW]";

            // STEP 2: Set up the OAuth 2.0 object

            // OAuth2Parameters holds all the parameters related to OAuth 2.0.
            OAuth2Parameters parameters = new OAuth2Parameters();

            // Set your OAuth 2.0 Client Id (which you can register at
            parameters.ClientId = CLIENT_ID;

            // Set your OAuth 2.0 Client Secret, which can be obtained at
            parameters.ClientSecret = CLIENT_SECRET;

            // Set your Redirect URI, which can be registered at
            parameters.RedirectUri = REDIRECT_URI;

            // STEP 3: Get the Authorization URL

            // Set the scope for this particular service.
            parameters.Scope = SCOPE;

            // Get the authorization url.  The user of your application must visit
            // this url in order to authorize with Google.  If you are building a
            // browser-based application, you can redirect the user to the authorization
            // url.
            string authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters);
            Console.WriteLine("Please visit the URL above to authorize your OAuth "
              + "request token.  Once that is complete, type in your access code to "
              + "continue...");
            parameters.AccessCode = Console.ReadLine();

            // STEP 4: Get the Access Token

            // Once the user authorizes with Google, the request token can be exchanged
            // for a long-lived access token.  If you are building a browser-based
            // application, you should parse the incoming request token from the url and
            // set it in OAuthParameters before calling GetAccessToken().
            string accessToken = parameters.AccessToken;
            Console.WriteLine("OAuth Access Token: " + accessToken);

            // STEP 5: Make an OAuth authorized request to Google

            // Initialize the variables needed to make the request
            GOAuth2RequestFactory requestFactory =
                new GOAuth2RequestFactory(null, "MySpreadsheetIntegration-v1", parameters);
            SpreadsheetsService service = new SpreadsheetsService("MySpreadsheetIntegration-v1");
            service.RequestFactory = requestFactory;

            // Make the request to Google
            // See other portions of this guide for code to put here...


Open in new window

- Is my error due to the wrong SCOPE?
- Or could it be that i never enable some google APIs?

Hope to hear some advice. Thanks!
Question by:divetennis
    1 Comment
    LVL 12

    Accepted Solution

    The error clearly says you are not providing the access_code to the api, that's the reason for the error.

    google oauth documentation specifies
    To begin, you obtain OAuth 2.0 credentials from the Google Developers Console. Then your client application requests an access token from the Google Authorization Server, extracts a token from the response, and sends the token to the Google API that you want to access.

    may be the below link could help you more.
    Using OAuth 2.0 for Login (OpenID Connect)

    hope this helps.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    One of my favorite tools to use with Google Drive is the offline access. Setting up offline access for Google Drive makes it easier for users to edit and view their docs, sheets and slides without Internet connection. Follow these steps to learn how…
    If your app took Google’s lash recently, here are the 5 most likely reasons.
    This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.
    This Micro Tutorial demonstrates in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now