我在PHP初學者,我想用一臺服務器上的PHP腳本從我trello帳戶的一些信息(這裏本地主機 - > WAMP)獲取信息使用trello API PHP
我用一個簡單的PHP我在互聯網上找到的代碼可以向trello api發出一些請求。
它是由位於trello-API類(trello-api.php)
<?php
class trello_api {
private $key;
private $secret;
private $token;
public function __construct ($key, $secret, $token) {
$this->key = $key;
$this->secret = $secret;
$this->token = $token;
}
public function request ($type, $request, $args = false) {
if (!$args) {
$args = array();
} elseif (!is_array($args)) {
$args = array($args);
}
if (strstr($request, '?')) {
$url = 'https://api.trello.com' . $request . '&key=' . $this->key . '&token=' . $this->token;
} else {
$url = 'https://api.trello.com' . $request . '?key=' . $this->key . '&token=' . $this->token;
}
$c = curl_init();
curl_setopt($c, CURLOPT_HEADER, 0);
curl_setopt($c, CURLOPT_VERBOSE, 0);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $url);
if (count($args)) curl_setopt($c, CURLOPT_POSTFIELDS , http_build_query($args));
switch ($type) {
case 'POST':
curl_setopt($c, CURLOPT_POST, 1);
break;
case 'GET':
curl_setopt($c, CURLOPT_HTTPGET, 1);
break;
default:
curl_setopt($c, CURLOPT_CUSTOMREQUEST, $type);
}
$data = curl_exec($c);
curl_close($c);
return json_decode($data);
}
}
?>
我把文件中的WAMP目錄../www/trello/trello-api.php
我創造了另一個index.php文件
<?php
require "./trello_api.php";
$key = 'my_key';
$secret = 'my_secret';
$token = 'my_token';
$trello = new trello_api($key, $secret, $token);
$data = $trello->request('GET', ('1/boards/'));
echo $data;
?>
$ data變量是空的,而不是與主板列表
返回JSON文件3210有人知道如何讓這段代碼有效嗎?
檢查,如果它是你任何幫助此鏈接:http://blog.clarkrasmussen.com/2013/06/25/php-and-the-trello-api/ –