作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 Google Docs 电子表格,我想用它来更新 Trello 中的引用卡片。我在 oauth 和通过他们的 HTTP API 提取数据方面取得了一些成功,但我坚持以下几点:
1) 似乎 Trello 的 code.js 需要一个 window 对象,而 Google Doc 脚本没有提供。所以,我坚持使用他们的 HTTP API。
2) 通过 OAuth 进行身份验证有效,但只给我读取权限。我无法使用我能够获得的 token 更新卡片。
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());
}
最佳答案
为了获得写入权限,您需要更改授权 url。
这个例子对我有用
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-apps-script - 如何从 Google 文档脚本授权和发布/更新 Trello 卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19597327/
我是一名优秀的程序员,十分优秀!