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

  • Home
  • SEARCH
  • 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 9127723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:20:56+00:00 2026-06-17T07:20:56+00:00

I’m trying to access a private Google Spreadsheet using Javascript. I have sucessfully authorized

  • 0

I’m trying to access a private Google Spreadsheet using Javascript. I have sucessfully authorized with OAuth2.0 and can see a listing of all my Google Drive docs. What I can’t seem to do is get into a specific spreadsheet. Code is as follows with the relevant spreadsheet code in the function “retrieveAllFiles”. A lot of this is culled from Google tutorials.

var clientId = 'working';
var apiKey = 'working';
var scopes = 'https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/drive https://spreadsheets.google.com/feeds';

function handleClientLoad() {
    console.log('inside handleClientLoad function');
    gapi.client.setApiKey(apiKey);
    window.setTimeout(checkAuth,1);
}

function checkAuth() {
    console.log('inside checkAuth function');
    gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true}, handleAuthResult);
    console.log('finished checkAuth function');
}

function handleAuthResult(authResult) {
    console.log('inside handleAuthResult function');
    var authButton = document.getElementById('authButton');
    authButton.style.display = 'none';
    if (authResult && !authResult.error) {
        //Access token has been succesfully retrieved, requests can be sent to the API.
        apiCalls();
    } else {
        //No access token could be retrieved, show the button to start the authorization flow.
        authButton.style.display = 'block';
        authButton.onclick = function() {
            gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: false}, handleAuthResult);
        };
    }
}

function apiCalls() {
    console.log('inside apiCalls function');
    gapi.client.load('drive', 'v2', function() {
         retrieveAllFiles(callback);
    });
}

function retrieveAllFiles(callback) {
     $.get('http://spreadsheets.google.com/feeds/spreadsheets/private/full', function(data) {
        console.log('get request processed');
        console.log(data);
    });
    console.log('inside retrieveAllFiles function');
    var retrievePageOfFiles = function(request, result) {
        request.execute(function(resp) {
        result = result.concat(resp.items);
        var nextPageToken = resp.nextPageToken;
        if (nextPageToken) {
            request = gapi.client.drive.files.list({
                'pageToken': nextPageToken
            });
            retrievePageOfFiles(request, result);
        } else {
            callback(result);
        }
        });
    }
    var initialRequest = gapi.client.drive.files.list();
    retrievePageOfFiles(initialRequest, []);
}

function callback(result) {
    console.log('all should be loaded at this point');
    console.log(result);
    $('#drive-list').append('<ul class="items"></ul>');
    $.map(result, function(v,i){
        $('.items').append('<li>' + v.title + ':' + v.id + '</li>');
    });
}

So to be clear, the end result currently is a listing of all my Google Drive docs, but no console.log for “get data processed”. I’m not getting any error messages in the console, so I can’t tell what is going on.

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-17T07:20:57+00:00Added an answer on June 17, 2026 at 7:20 am

    Final solution compiled from a bunch of different sources, hopefully this will help someone.

    var scopes = 'https://spreadsheets.google.com/feeds';
    var clientId = 'working';
    var apiKey = 'working';
    
    function handleClientLoad() {
        console.log('inside handleClientLoad function');
        gapi.client.setApiKey(apiKey);
        window.setTimeout(checkAuth,1);
    }
    
    function checkAuth() {
        console.log('inside checkAuth function');
        gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true}, handleAuthResult);
        console.log('finished checkAuth function');
    }
    
    function handleAuthResult(authResult) {
        console.log('inside handleAuthResult function');
        console.log(gapi.auth.getToken());
        var authButton = document.getElementById('authButton');
        authButton.style.display = 'none';
        if (authResult && !authResult.error) {
            //Access token has been successfully retrieved, requests can be sent to the API.
            loadClient();
        } else {
            //No access token could be retrieved, show the button to start the authorization flow.
            authButton.style.display = 'block';
            authButton.onclick = function() {
                gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: false}, handleAuthResult);
            };
        }
    }
    
    function loadClient() {
        console.log('inside loadClient function');
        var token = gapi.auth.getToken().access_token;
        var urlLocation = ''; //Get this from the URL of your Spreadsheet in the normal interface for Google Drive.
    
        //This gives a spitout of ALL spreadsheets that the user has access to.
        var url = 'https://spreadsheets.google.com/feeds/spreadsheets/private/full?access_token=' + token;
    
        //This gives a list of all worksheets inside the Spreadsheet, does not give actual data
        var url = 'https://spreadsheets.google.com/feeds/worksheets/' + urlLocation + '/private/full?access_token=' + token;
    
        //This gives the data in a list view - change the word list to cells to work from a cell view and see https://developers.google.com/google-apps/spreadsheets/#working_with_cell-based_feeds for details
        var url = 'https://spreadsheets.google.com/feeds/list/' + urlLocation + '/od6/private/full?access_token=' + token;
    
        console.log(url);
        $.get(url, function(data) {
            console.log(data);
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I have a small JavaScript validation script that validates inputs based on Regex. I
I am trying to render a haml file in a javascript response like so:
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the

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.