Ich bin ein Anfänger in php und ich möchte ein PHP-Skript auf einem Server einige Informationen von meinem Trello Konto erhalten mit (hier localhost -> wamp)Informationen erhalten Trello API PHP
verwendete ich ein einfaches PHP Code, den ich im Internet gefunden habe, um einige Anfragen an das Trello api zu stellen.
Es ist in einer Trello-api-Klasse (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);
}
}
?>
Ich habe die Datei im Verzeichnis wamp ../www/trello/trello-api.php
besteht ich habe eine andere Datei 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;
?>
die Variable $ data ist null statt die jSON-Datei mit der definierten Liste Rückkehr
Weiß jemand, wie man diesen Code funktioniert?
prüfen Sie diesen Link, wenn es keine Hilfe für Sie: http://blog.clarkrasmussen.com/2013/06/25/php-und-der-trello-api/ –