-
-
Save projektorius96/1d39bc622e2dfb7777cfcc5afd65e79b to your computer and use it in GitHub Desktop.
Revisions
-
skauk revised this gist
Feb 8, 2013 . 1 changed file with 12 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,6 +22,18 @@ function uploadPdfOcr() { return DocsList.getFileById(uploadResponse.id); } function convert(fileId) { authorize(); var key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // <-- developer key var params = {method:"post", oAuthServiceName: "drive", oAuthUseToken: "always" }; var uploadRequest = UrlFetchApp.fetch("https://www.googleapis.com/drive/v2/files/"+fileId+"/copy?convert=true&key="+key, params); var uploadResponse = Utilities.jsonParse(uploadRequest.getContentText()); return DocsList.getFileById(uploadResponse.id); } function authorize() { var oauthConfig = UrlFetchApp.addOAuthService("drive"); var scope = "https://www.googleapis.com/auth/drive"; -
skauk created this gist
Dec 30, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ function uploadPdfOcr() { authorize(); var key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // <-- developer key var file = UrlFetchApp.fetch("http://somewhere.com/path/file.pdf").getBlob(); var metadata = { title: file.getName() } var params = {method:"post", oAuthServiceName: "drive", oAuthUseToken: "always", contentType: "application/pdf", contentLength: file.getBytes().length, payload: file.getBytes() }; var uploadRequest = UrlFetchApp.fetch("https://www.googleapis.com/upload/drive/v2/files/?uploadType=media&ocr=true&key="+key, params); var uploadResponse = Utilities.jsonParse(uploadRequest.getContentText()); var params = {method:"put", oAuthServiceName: "drive", oAuthUseToken: "always", contentType: "application/json", payload: Utilities.jsonStringify(metadata) }; var metaRequest = UrlFetchApp.fetch("https://www.googleapis.com/drive/v2/files/"+uploadResponse.id+"?key="+key, params) return DocsList.getFileById(uploadResponse.id); } function authorize() { var oauthConfig = UrlFetchApp.addOAuthService("drive"); var scope = "https://www.googleapis.com/auth/drive"; oauthConfig.setConsumerKey("anonymous"); oauthConfig.setConsumerSecret("anonymous"); oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope); oauthConfig.setAuthorizationUrl("https://accounts.google.com/OAuthAuthorizeToken"); oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken"); }