Unexpected exception after serialization of continuation

I get this error: Unexpected exception after serializing a continuation (not many)

This is called FetchUrlApp.fetch (); call. I use Google Apps Script for sites, not for Google spreadsheets. The code works in the original instance, but as soon as I copy and paste the code into a new project, I get the above error message. I am referring to the Google Docs APIs. I read on other forums that I need authorization, but I could not get the correct permission to operate the code. When I run a copy of the code for the first time, tooltips never appear.

Exert code:

var oauthConfig = UrlFetchApp.addOAuthService("docs"); oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken"); oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope=https://docs.google.com/feeds/"); oauthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken"); oauthConfig.setConsumerKey(_consumerKey_); oauthConfig.setConsumerSecret(_consumerSecret_); var requestData3 = { "method": "GET", "headers": {"GData-Version": "3.0"}, "oAuthServiceName": "docs", "oAuthUseToken": "always", }; var url = "https://docs.google.com/feeds/" + userName + "/private/full/-/mine"; var result = UrlFetchApp.fetch(url, requestData3); //error occurs, any thoughts? 

Thanks in advance James Crimm

+3
source share
2 answers

In order to initiate a three-way OAuth process, you must set "userKey" and "userSecret" as "anonymous":

 oauthConfig.setConsumerKey("anonymous"); oauthConfig.setConsumerSecret("anonymous"); 

Replace these two lines with them, and an authorization pop-up dialog will appear, allowing the user to provide access to his documents.

0
source

I would suggest writing a special function that does nothing but call the Oauth process and call it from the script editor once. As an example, here is the one I used recently to create an authorization popup:

 function authorize(){ // function to call from the script editor to authorize googleOauth var id=mailtemplatedoc var url = 'https://docs.google.com/feeds/'; var doc = UrlFetchApp.fetch(url+'download/documents/Export? exportFormat=html&format=html&id='+id, googleOAuth_('docs',url)).getContentText(); } 

EDIT: And the missing part that I forgot:

 function googleOAuth_(name,scope) { var oAuthConfig = UrlFetchApp.addOAuthService(name); oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope); oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken"); oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken"); oAuthConfig.setConsumerKey('anonymous'); oAuthConfig.setConsumerSecret('anonymous'); return {oAuthServiceName:name, oAuthUseToken:"always"}; } 
0
source

All Articles