邀请Trello API的人
我想邀请一个人通过电子邮件从我的网站Trello。这里是API reference。当我尝试邀请他时,简单回复是“无效密钥”。这里是我的功能:邀请Trello API的人
public function inviteEmployeeToTrello ($email, $name, $isAdmin)
{
$organazationTrelloID = 'myOrganazationID';
$trelloAuthToken = 'myTrelloAuthToken';
$trelloInviteUrl = 'https://trello.com/1/organizations/'.$organazationTrelloID.'/members';
if ($isAdmin == 1)
{
$type = 'admin';
}
else
{
$type = 'normal';
}
$fields = array(
'fullName' => $name,
'email' => $email,
'type' => $type,
'token' => $trelloAuthToken
);
// open connection
$ch = curl_init();
// set the url, number of PUT vars, PUT data
curl_setopt($ch, CURLOPT_URL, $trelloInviteUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// exec
$replyRaw = curl_exec($ch);
$reply = json_decode($replyRaw, true);
// close connection
curl_close($ch);
dd($ch);
}
CURLOPT_POSTFIELDS不想要一个JSON, 如果你想要一个urlencoded请求,使用http_build_query($ fields),或者如果你想要一个multipart/form-data请求,直接给它$ fields数组。 (API文档似乎没有提及它接受哪种请求类型,urlencoded是最常见的。)
由于错误代码说,你忘了通过你的application key。下面是来自API reference一个例子:
https://api.trello.com/1/organizations/publicorg?members=all&member_fields=username,fullName&fields=name,desc&键= [application_key] &令牌= [optional_auth_token]
你必须把它列入您的查询,因此你的情况,将其添加到在 $fields
阵列:
$fields = array(
'fullName' => $name,
'email' => $email,
'type' => $type,,
'key' => $trelloAppKey
'token' => $trelloAuthToken
);
谢谢!我已将我的密钥添加到$ field数组,并用http_build_query($ fields)替换了json_encode($ fields),现在它可以工作了! – coolside
谢谢!我已将我的密钥添加到$ field数组,并用http_build_query($ fields)替换了json_encode($ fields),现在它可以工作了! – coolside