title: Can I check if a google doc is publicly available through the Google Drive API without logging into Google?
body: <p>I'm trying to create a client side (javascript) application that tests whether a specific Google Doc is public or private, and I would like to be able to get that info without my user logging into Google.  (If the document is public, then there's no reason to prompt people to login to Google unnecessarily in order to view it.)</p>
  
  <p>So to begin with: I have created a Google project. I have created a client ID for my web application and an api key for browser applications.  (And I have activated the Google Drive api.)</p>
  
  <p>Here's my prototype code:</p>
  
  <pre><code>&lt;script src="https://apis.google.com/js/client.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  
  var LOGGED_INTO_GOOGLE;
  
  // initiates the test when the page has loaded
  function start_test()
  {
    checkAuth( true );
  }
  
  // checks if the user is logged into google
  // if immediate = false, google supplies a login window to those who are not logged in
  // otherwise this just sets LOGGED_INTO_GOOGLE to true or false
  function checkAuth(immediate)
  {
    CLIENT_ID = 'xxxxxxxxxx.apps.googleusercontent.com';
    SCOPES = [
      'https://www.googleapis.com/auth/drive',
      'https://www.googleapis.com/auth/userinfo.email',
      'https://www.googleapis.com/auth/userinfo.profile'
    ];
    gapi.auth.authorize( {'client_id': CLIENT_ID, 'scope': SCOPES.join(' '), 'immediate': immediate}, handleAuthResult );
  }
  
  // the callback function for checkAuth
  // it loads the GoogleDrive api on success
  function handleAuthResult(authResult)
  {
    if (authResult)
    {
      LOGGED_INTO_GOOGLE = authResult.status.signed_in;
      console.log( "loggedin? "+ LOGGED_INTO_GOOGLE );
      loadClient();
    }
    else
    {
      checkAuth(false);
    }
  }
  
  // loads the GoogleDrive api and then gets our test google doc
  function loadClient()
  {
    gapi.client.load('drive', 'v2', getFile);
  }
  
  // The PUBLIC GOOGLE DOC we are testing is: https://docs.google.com/document/d/1tlwvDhmL76p3YEUwOuL55oPwea9vrKo-8LuGoVoYcqg/edit?pli=1
  // this gets the permissions for the doc
  function getFile()
  {
    var request = gapi.client.drive.files.get({'fileId': '1tlwvDhmL76p3YEUwOuL55oPwea9vrKo-8LuGoVoYcqg', 'fields': 'permissions'});
    request.execute( handleFileRequest );
  }
  
  // This handles the request
  // I expect the permissions parameter to be set when one of two conditions are met:
  // 1) the user is logged in and has access to the file (public or private); OR
  // 2) the user is NOT logged in, but the file is PUBLIC.
  function handleFileRequest( resp )
  {
    console.log( resp );
    if ( !resp.permissions )
    {
      console.log( "no permissions" );
      if( !LOGGED_INTO_GOOGLE )
      {
        console.log( "not logged into google" );
        return;               
      }
      else
      {
        console.log( "YES logged into google" );
        return;
      }
    }     
    console.log( "YES! permissions" );
  }
  
  window.onload = start_test;
  &lt;/script&gt;
  </code></pre>
  
  <p>In earlier tests of this script, this appeared to work as I assumed:  If a person is logged out of Google, but we try to access a public document (like "1tlwvDhmL76p3YEUwOuL55oPwea9vrKo-8LuGoVoYcqg"), I still got "YES! permissions".  Now, for reasons I do not understand, that is not working.  The response I get is this:</p>
  
  <pre><code>{code: 403, message: "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.", data: Array[1], error: Object}
  </code></pre>
  
  <p>That would make sense for private documents.  But the public google docs are freely available; I'm not sure why the api would constrict access to their meta info. </p>
  
  <p>One note (that may or may not be important): I only send my client id to Google when I fire the gapi.auth.authorize function.   I do not send the client id, my api credential or any other authorization token when I use the drive api (gapi.client.drive.files.get).  Is there something I'm missing there?  That wasn't very clear in the google drive documentation.</p>
  
  <p>I would appreciate anyone's advice who has more experience with google's api than me.
  thanks. -D</p>