Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Got some time to look into it again :( its a bit of a hack but should work</p> <ul> <li>You will need to get setup a project using the API console in order to get your CONSUMER_KEY and CONSUMER_SECRET ... its also important to set the redirect URI's and origin for the call back properly <a href="https://script.google.com/oauth2callback" rel="nofollow">https://script.google.com/oauth2callback</a> and <a href="https://script.google.com" rel="nofollow">https://script.google.com</a> respectively seems to work for me :)</li> </ul> <blockquote> <p>Here is the API Console <a href="https://developers.google.com/console/help/" rel="nofollow">HELP PAGE</a> you should create a project which will require you to sign in with your google credentials. If this is the first time to you are login in to the API you will get a large button to create your first project. You should then get credentials for a web application client. The CONSUMER_KEY and CONSUMER_SECRET are found when you click on the API Access link and are called 'Client ID' and 'Client secret'. </p> </blockquote> <ul> <li>Be sure to select the Drive API service.</li> </ul> <blockquote> <p>Once the project is created, the console will appread, click on services (link on the right), scroll down and click on the Drive API toggle to enable it.</p> </blockquote> <ul> <li>Using the ID of the uploaded file you can download its content using urlFetch </li> </ul> <blockquote> <p>The file you just upload as an ID you can get it using docID = doc.getId()</p> </blockquote> <ul> <li>You will need to authorise the OAuth flow</li> </ul> <blockquote> <p>Basically the first time you run the script, it will go through authorisation flow, that will enable your application to access your drive resources, as you might see the scope selected by the app is read-only "www.googleapis.com/auth/drive.readonly" you can learn more about the Drive API <a href="https://developers.google.com/drive/v2/reference/" rel="nofollow">HERE</a></p> </blockquote> <ul> <li>I have done this in a Spreadsheet to view the Logger statement, surely you can port it to a non spreadsheet bound script.</li> </ul> <blockquote> <p>Developing in spreadsheets provide better debuggin capabilities after which we can port the code to a standalone script. The difference is that to show a UI you need to call the active spreadsheet and call .show(app) on it ... info about this here : <a href="https://developers.google.com/apps-script/uiapp#DisplayingSpreadsheet" rel="nofollow">https://developers.google.com/apps-script/uiapp#DisplayingSpreadsheet</a></p> </blockquote> <p>Code:</p> <pre><code>function getFileContent(docId) { //set up oauth for Google Drive Settings var oAuthConfig1 = UrlFetchApp.addOAuthService("googleDrive2"); oAuthConfig1.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope=https://www.googleapis.com/auth/drive.readonly"); oAuthConfig1.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken"); oAuthConfig1.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken?oauth_callback=https://script.google.com/a/macros"); oAuthConfig1.setConsumerKey(CONSUMER_KEY); oAuthConfig1.setConsumerSecret(CONSUMER_SECRET); var options1 = {oAuthServiceName:"googleDrive2", oAuthUseToken:"always", method:"GET", headers:{"GData-Version":"3.0"}, contentType:"application/x-www-form-urlencoded"}; //set up drive file url var theUrl = "https://www.googleapis.com/drive/v2/files/" + docId; //urlFetch for drive metadat info var fileMetadata = ""; try { var response = UrlFetchApp.fetch(theUrl,options1); fileMetadata = response.getContentText(); } catch(problem) { Logger.log(problem.message); } // find the download Url var fileDownloadUrl = Utilities.jsonParse(fileMetadata).downloadUrl; Logger.log(fileDownloadUrl) var fileContent = ""; try { var response = UrlFetchApp.fetch(fileDownloadUrl,options1); fileContent = response.getContentText(); } catch(problem) { Logger.log(problem.message); } Logger.log(fileContent); } </code></pre> <p>Let me know how that works.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload