2015-05-28 43 views
0

我已經在這裏查看了答案:How do I stop the error, Authorisation is required to perform that action in Google Script。這並不能解決我的問題,因爲我沒有更改我的任何代碼,並且在第一次運行代碼時我已經授權了代碼。突然間,我得到了Authorization is required to perform that action錯誤。「執行該操作需要授權」突然在沒有更改代碼後

我也試過這個鏈接https://developers.google.com/apps-script/troubleshooting#common_errors並且在編輯器function test() { var a=1}中運行了一個空白函數。這運行正常,沒有給我一個提示來授權腳本並沒有錯誤。因此,在遵循Google的指示後:To authorize the script, open the Script Editor and run any function.我仍然收到Authorization is required to perform that action錯誤。

我沒有做任何奇特的事情。該腳本只有一個.gs文件,並且該文件只有一個功能。我沒有使用任何高級服務,也沒有將它鏈接到任何庫。

更新:我試圖製作一個文件的副本,然後我再次進入腳本編輯器運行代碼。這次授權彈出窗口在那裏,所以我點擊繼續。後續顯示出來:代碼想

View and manage the files in your Google Drive. Send email as you Connect to an external service

我點擊「接受」。代碼開始運行,2秒後Authorization is required to perform that action.現在,每次我嘗試運行代碼時,它甚至不會授予我彈出的授權。它只是給了我錯誤。

這裏是代碼的oauth部分。其餘的代碼只是更多的幾行。

var oauthConfig = UrlFetchApp.addOAuthService("google"); 
    var scope = "https://docs.google.com/feeds/"; 

    //make OAuth connection 
    oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken"); 
    oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope); 
    oauthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken"); 
    oauthConfig.setConsumerKey("anonymous"); 
    oauthConfig.setConsumerSecret("anonymous"); 

    //get request 
    var request = { 
    "method": "GET", 
    "oAuthServiceName": "google", 
    "oAuthUseToken": "always", 
    "muteHttpExceptions": true 
    }; 
+0

您是否使用任何高級的谷歌服務? –

+0

我在腳本編輯器中查看參考資料部分。一切都關閉了。我沒有使用任何高級服務。 – jason

+0

以前的代碼有效嗎?如果沒有,你可以發佈它,以便我們可以檢查錯誤是否在你的代碼中? –

回答

1

UrlFetchApp中的oauthConfig已被棄用。它在6月26日被關閉。以下鏈接將向您展示如何將代碼從oauthConfig遷移到Oauth1庫。
https://developers.google.com/apps-script/migration/oauth-config

編輯: 從它看起來像你想的電子表格保存在驅動器中的PDF格式的意見。這裏有一段代碼可以做到這一點。

var ss = SpreadsheetApp.openById(fileId); 
    var blob = ss.getBlob().setName("new_file_name.pdf"); 
    DriveApp.createFile(blob); 
+0

這似乎是錯誤。但從你的鏈接看來,Oauth1也被關閉。鏈接https://github.com/googlesamples/apps-script-oauth2給我帶來一些麻煩。所有我想要做的是這個http://stackoverflow.com/questions/12881547/exporting-spreadsheet-to-pdf-then-saving-the-file-in-google-drive但「Docslist」不再有效。 – jason

+0

添加了一些代碼,以顯示如何將電子表格轉換爲pdf並將其保存到驅動器。 –

+0

謝謝Spencer。我更加期待oauth2的一部分。其他代碼我以前有過。如果你想嘗試這個問題,請成爲我的客人。 http://stackoverflow.com/questions/30586559/printing-spreadsheet-to-pdf-then-saving-file-in-drive-using-oauth2。我意識到這是遷移到oauth2代碼對我來說很困難 – jason

相關問題