Javascript 如何使用TrelloJSAPI创建卡
我一直在尝试利用via-JSFiddle,但未能使其正常工作(我的JS/JSON知识非常有限)。我需要使用API在特定列表下创建一张卡Javascript 如何使用TrelloJSAPI创建卡,javascript,jquery,json,api,trello,Javascript,Jquery,Json,Api,Trello,我一直在尝试利用via-JSFiddle,但未能使其正常工作(我的JS/JSON知识非常有限)。我需要使用API在特定列表下创建一张卡 function PostStuff() { $(document).ready(function(){ Trello.authorize({ interactive: true, type: "popup", expiration: "never", name: "
function PostStuff()
{
$(document).ready(function(){
Trello.authorize({
interactive: true,
type: "popup",
expiration: "never",
name: "surveyrequest",
persist: "true",
success: function() { onAuthorizeSuccessful(); },
error: function() { onFailedAuthorization(); },
scope: { read: true, write: true}
});
function onAuthorizeSuccessful() {
Trello.post("cards", { name: "Card created for test", desc: "this is a test", idList: "........", due: null, urlSource: null});
}
});
}
我有JQuery和TrelloAPI。为了安全起见,我把代码中的空闲者删掉了。我确认代码确实执行了onAuthorizeSuccessful()函数
我如何修改它来创建Trello卡
function Auth() {
Trello.authorize({
type: 'popup',
name: 'your app name',
scope: {
read: true,
write: true },
expiration: '30days',
success: authenticationSuccess,
error: authenticationFailure
});
var authenticationSuccess = function(data){ /*your function stuff*/};
var authenticationFailure = function(data){ /*your function stuff*/};
}
这个代码对我有用。我在单击按钮时触发函数Auth()
此外,您可能会对过期的令牌产生一些问题,因此Trello.deauthorize()代码>可用于创建新卡故障功能(完全取决于创建新卡错误消息)
关于创建一张新卡
var newCard =
{name: jQuery('input#tc_title').val(),
desc: jQuery('textarea#tc_desc').val(),
pos: "top",
idList: trello_list_id_var
};
Trello.post('/cards/', newCard, success, error);
var success = function(data){ /*..............*/}
var error= function(data){ /*..............*/}
在成功/错误函数中,您可以检查错误数据
编辑:
另外,我认为Trello.post(“cards”…
应该替换为Trello.post(“/cards/”)…
,这可能是问题所在……您可能想尝试向Trello.post
添加一个错误处理程序,以便找出它不起作用的原因。