Unexpected exception upon serializing continuation

天大地大妈咪最大 提交于 2019-11-29 15:17:48

You have to set both consumerKey and consumerSecret to "anonymous" in order to trigger the 3-legged OAuth process:

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

Replace your two lines with these and the authorization popup dialog will show up, allowing the user to grant access to its documents.

What I would suggest is to write a special function that does nothing else than call the Oauth process and call it from the script editor once. As an example, here is the one I have used recently to make the authorize popup appear :

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 I had forgotten :

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"};
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!