我对api很新,想做以下事情: 使用我页面上的表单将新卡发布到trello板。 Trello提供api,但我真的不知道如何使用它: http://mattzuba.bitbucket.org/php-trello/
我的表单如下:
<form id="trello" class="form-horizontal">
<div class="form-group">
<div class="col-md-6">
<input type="text" name="Name" placeholder="Name" class="form-control" />
</div>
<div class="col-md-6">
<input type="email" name="email" placeholder="eMail" class="form-control" />
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input type="text" name="Title" placeholder="Title" class="form-control" />
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<textarea name="content" cols="40" rows="10" placeholder="Content" class="form-control"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input type="file" name="attachment" value="1" class="form-control">
</div>
</div>
<div class="form-group">
<a class="btn btn-primary" id="submit">Submit</a>
</div>
</form>
现在我要创建一张看起来像这样的卡片:
card-name: $title
card-content: $content
Submitted by: $name ($email)
card-attachment: $attachment
因为这个表格应该是公开的(使用验证码),oAuth对我来说是不可能的:/
我不知道如何存档:/ 如果有人给我一个例子,那就太棒了:))
有人能帮助我吗?
答案 0 :(得分:2)
我已将以下代码放在一起,它对我有用。
<?php
if ($_POST) {
$card_name = htmlspecialchars($_POST['title']);
$card_content = htmlspecialchars($_POST['content']) . "\n";
$card_content .= htmlspecialchars($_POST['name']) . " (" . htmlspecialchars($_POST['email']) . ")";
$trello_key = 'YourTrelloApiKey';
$trello_api_endpoint = 'https://api.trello.com/1';
$trello_list_id = 'IdOfListYouArePostingTo';
$trello_member_token = 'AnApplicationTokenYouHaveGenerated'; // Guard this well
$url = 'https://api.trello.com/1/cards';
$fields='token='.$trello_member_token;
$fields.='&key='.$trello_key;
$fields.='&idList='.$trello_list_id;
$fields.='&name='.$card_name;
$fields.='&desc='.$card_content;
$result = trello_post($url, $fields);
}
function trello_post($url, $fields){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$output = curl_exec($ch);
curl_close($ch);
return json_decode($output);
}
?>
<form id="trello" method="post" class="form-horizontal">
<div class="form-group">
<div class="col-md-6">
<input type="text" name="name" placeholder="Name" class="form-control" />
</div>
<div class="col-md-6">
<input type="email" name="email" placeholder="E-Mail" class="form-control" />
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input type="text" name="title" placeholder="Title" class="form-control" />
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<textarea name="content" cols="40" rows="10" placeholder="Content" class="form-control"></textarea>
</div>
</div>
<div class="form-group">
<input type="submit" value="Submit">
</div>
</form>
&#13;
我没有工作的唯一方面是附件上传。很少有文档可以支持这一点。