How to authorize and post/update Trello card from a Google docs script

梦想与她 提交于 2019-12-03 05:06:14

In order to get write access, you need to change the authorization url. This example works for me

  var oauthConfig = UrlFetchApp.addOAuthService("trello");
  oauthConfig.setAccessTokenUrl("https://trello.com/1/OAuthGetAccessToken");
  oauthConfig.setRequestTokenUrl("https://trello.com/1/OAuthGetRequestToken");
  oauthConfig.setAuthorizationUrl("https://trello.com/1/OAuthAuthorizeToken?scope=read,write");

on 1) yes you cant use the library from server gas, its meant to be run from a browser. on 2), Ive done it from GAS with write access without problems. You need to use the format: https://api.trello.com/1/.../xxxx?key=yyyyyy&token=zzzzzzz&...

and when you get the token, you need to request permanent access (no expiration) and write access, as in: https://trello.com/1/authorize?key="+key+"&name=xxxxxxx&expiration=never&response_type=token&scope=read,write"

As in:

function postNewCardCommentWorker(cardId, comment, key, token) {

  var commentEncoded=encodeURIComponent(comment);
  var url = "https://api.trello.com/1/cards/"+cardId+"/actions/comments?text="+commentEncoded+"&key="+key+"&token="+token;
  var options =
     {
       "method" : "POST"
     };

  UrlFetchApp.fetch(url, options);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!