如何从Google文档脚本中授权并发布/更新Trello卡 [英] How to authorize and post/update Trello card from a Google docs script

查看:295
本文介绍了如何从Google文档脚本中授权并发布/更新Trello卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Google文档电子表格,我想用来更新Trello的参考卡。我已经取得了一些成功的oauth并通过他们的HTTP API提取数据,但我坚持下列:



1)似乎Trello的code.js需要一个窗口对象,Google Doc脚本不提供。所以,我被卡住了使用他们的HTTP API。



2)通过OAuth进行身份验证工作,但只给我阅读权限。我无法使用令牌获得更新卡。

  function test(){
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/authorize?key=+ consumerKey +& name = trello& expiration = never& response_type = token& scope = read,write);
//oauthConfig.setAuthorizationUrl(\"https://trello.com/1/OAuthAuthorizeToken); < - 这仅给予读访问。无法POST
oauthConfig.setConsumerKey(consumerKey);
oauthConfig.setConsumerSecret(consumerSecret);

var url ='https://trello.com/1/cards/yOqEgvzb/actions/comments& text = Testing ...';
var postOptions = {method:post,
oAuthServiceName:trello,
oAuthUseToken:always};

var response = UrlFetchApp.fetch(url,postOptions); //请求失败返回代码404.截断的服务器响应:不能POST

Logger.log(response.getContentText());
}

我发现了一些相关问题,但没有直接的答案: p>

如何使用Trello API获取永久用户令牌?



Trello API:在卡上投票



Trello API:如何从Google Apps脚本中发卡(GAS)



Google应用脚本oauth connect不适用于trello



非常感谢提前提供任何建议。

解决方案

为了获得写入权限,您需要更改授权网址。
此示例适用于我

  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);


I have a Google Docs Spreadsheet that I'd like to use to update referenced cards in Trello. I've had some success with oauth and pulling data via their HTTP API, but am stuck with the following:

1) it seems Trello's code.js requires a window object, which the Google Doc script doesn't provide. So, I am stuck using their HTTP API.

2) authenticating via OAuth works, but only gives me read access. I cannot update cards with the token I am able to get.

function test() {
  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/authorize?key=" + consumerKey + "&name=trello&expiration=never&response_type=token&scope=read,write");
  //oauthConfig.setAuthorizationUrl("https://trello.com/1/OAuthAuthorizeToken");  <-- this only gives read access.  Cannot POST
  oauthConfig.setConsumerKey(consumerKey);
  oauthConfig.setConsumerSecret(consumerSecret);

  var url = 'https://trello.com/1/cards/yOqEgvzb/actions/comments&text=Testing...';  
  var postOptions = {"method" : "post",
                   "oAuthServiceName": "trello",
                   "oAuthUseToken": "always"};

   var response = UrlFetchApp.fetch(url, postOptions);  // "Request failed for returned code 404. Truncated server response: Cannot POST"

   Logger.log(response.getContentText());
}

I've found a number of related questions but no direct answers:

How to get a permanent user token for writes using the Trello API?

Trello API: vote on a card

Trello API: How to POST a Card from Google Apps Script (GAS)

Google apps script oauth connect doesn't work with trello

Many thanks ahead of time for any advice.

解决方案

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");

这篇关于如何从Google文档脚本中授权并发布/更新Trello卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆