2013-01-17 4 views
0

웹 편집 대기열을 Trello에 통합/대체하려고합니다.Trello API PHP Curl

공용이 아니지만 읽기/쓰기 액세스 토큰을 생성 한 조직을 만들었습니다.

나는 Trello API에 대한 좋은 PHP 래퍼를 보지 못했다

은 (가능한 두 개의 살펴 보았다 정말 그들까지 내 목적을 위해 실행을 가져올 수 없습니다.)

을 어쨌든 , 내가 무엇을하고 싶습니다 해야할 일은 특정 목록에 카드를 읽고 삽입하는 다소 기본적인 액세스를 제공하는 것입니다.

내가 지금까지 다음과 같은 사용하여 목록의 결과를 반환하는 API를 사용하는 등 입수했습니다 :

https://api.trello.com/1/lists/[mylistID]/cards?key=[myappkey]&token=[mytoken] 

나는 결과로 정확히 원하는 것을 얻을, 목록에있는 카드의 JSON.

는 지금은, CURL을 사용하여 PHP에서 그것을 다시 노력하고있어 내가 다음 코드하려고 어떤에서 나는 무단 또는 잘못된 요청의 오류 응답을 받고 있어요 :

$url = "https://api.trello.com/1/lists/[myboardID]/cards"; 
$trello_key   = 'mykey'; 
$trello_list_id  = 'mylistid'; 
$trello_member_token = 'mytoken'; 

$fields = "key=$trello_key&token=$trello_member_token&name=$name&idList=$trello_list_id"; 
e 
# init curl 
$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, 1); 
curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE); // make sure we see the sended header afterwards 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_TIMEOUT, 0); 
curl_setopt($ch, CURLOPT_POST, 1); 

# dont care about ssl 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 

# download and close 
$output = curl_exec($ch); 
$request = curl_getinfo($ch, CURLINFO_HEADER_OUT); 
$error = curl_error($ch); 
curl_close($ch); 

그래서 난 그냥 해요 아무도 내가 뭘 잘못하고 있는지 알고 싶어. 나는 그것이 단순해야한다고 느낀다. 그러나 나는 그것에 두 사람의 시간을 보내었다. 그리고 나는 내가 약간의 도움을 필요로한다라고 생각한다. 아이디어가 있으면 알려주세요.

이 실제로 나를 위해 작동하는 것 같다

+0

첫 번째 오류 : 'Notice : 정의되지 않은 변수 : D : \ LAMP \ www \ a.php in line 21'에서 시도했습니다. '$ name'이 정의되어 있는지 확인하십시오. –

+0

죄송합니다. 방정식에서 이름을 빼낼 수 있습니다. 어쨌든, 나는 그것을 해결했다고 생각하지만, 여전히 응답을 파싱하는 방법을 정확히보고있다. – mmundiff

답변

2

{나는 내 API 키, 토큰, BoardID 등으로 분명한 언급을 떠난}. CURL을 사용하여 기본 GET 대신 POST를 사용하려고했습니다. 응답을 파싱하는 작업을하고 있지만 제대로 된 것 같습니다. 응답에서 "200 OK"를 얻었습니다.

$url = 'https://api.trello.com/1/lists/[myListID]/cards?key=[MyApiKey]&token=[myToken]'; 

# init curl 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
//curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded_fields); 
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); 
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE); // make sure we see the sended header afterwards 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_TIMEOUT, 0); 
//curl_setopt($ch, CURLOPT_POST, 1); 

# dont care about ssl 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 

# download and close 
$output = curl_exec($ch); 
$request = curl_getinfo($ch, CURLINFO_HEADER_OUT); 
$error = curl_error($ch); 
curl_close($ch); 

echo 'This is output = '.$output .'<br />'; 
echo 'This is request = '.$request .'<br />'; 
echo 'This is error = '.$error .'<br />';