简体   繁体   中英

Creating Trello cards with Google Apps and OAuth

I'm trying to build a Google Apps Script that integrates with Trello , the idea being to use it to push information from spreadsheets and forms into the Trello API and create cards on a pending list on a certain board.

I found another question that pointed me in the right direction, and added in OAuth based on the GAS OAuth Documentation . The problem is I can't post the the board. I run the script, the OAuth prompt fires, and the script completes with no errors. I can also GET data from the private board, so I assume the authorization is working properly.

So, what am I doing wrong that prevents my script from POST ing to Trello?

Here's the code I'm working with:

var trelloKey = [Trello API key];
var trelloSecret = [Trello API key secret];
var trelloList = [the id of the list we're posting to];

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');
    oauthConfig.setConsumerKey(trelloKey);
    oauthConfig.setConsumerSecret(trelloSecret);

function createTrelloCard() {

  //POST [/1/cards], Required permissions: write
  var payload = {'name': 'apiUploadedCard', 
                 'desc': 'description', 
                 'pos': 'top', 
                 'due': '', 
                 'idList': trelloList};

  var url = 'https://api.trello.com/1/cards'
  var options = {'method' : 'post',
                 'payload' : payload,
                 'oAuthServiceName' : 'trello',
                 'oAuthUseToken' : 'always'};

  UrlFetchApp.fetch(url, options);
}

You just need set fetch options contentType to application/json . I just resolved the same problem by this.

Try adding the scope=read,write in your authorization url.

from:

oauthConfig.setAuthorizationUrl('https://trello.com/1/OAuthAuthorizeToken');

to:

oauthConfig.setAuthorizationUrl("https://trello.com/1/OAuthAuthorizeToken?scope=read,write");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM