chartbeat/chartbeat-php
最新稳定版本:1.0.0
Composer 安装命令:
composer require chartbeat/chartbeat-php
包简介
PHP library for Chartbeat
关键字:
README 文档
README
PHP library to interact with Chartbeat API.
See great API docs and API explorer from Chartbeat website for more info.
This library requires PHP >5.3 and cURL extension for PHP to work. Tested with PHP 5.3.15 and 5.4.6
Please give feedback, report bugs, fork and contribute.
Installation
Add chartbeat-php to your composer.json:
{
"require" : {
"chartbeat/chartbeat-php" : "1.*"
}
}
Simple test script:
require_once ('vendor/autoload.php'); // composer autoloader $apiKey = '<your api key>'; $host = '<your host>'; $cb = new Chartbeat\Chartbeat($host, $apiKey); // get monthly max people on site echo 'Monthly max people on the site: ' . $cb->getMonthlyMaxPeople();
You can also do any kind of API query using get() method. First parameter is data endpoint (eg. 'historical/traffic/series'), seconds one contains parameters.
In here, we get top referer of page which has most visitors right now:
$cbData = $cb->get('live/toppages/v3/', array('limit' => 1)); // get all top pages, we want only 1 $topPage = current($cbData->pages); // get first page of the result var_dump(current($topPage->stats->toprefs)); // output first top referer of page // outputs: object(stdClass)#9 (2) { ["visitors"]=> int(10) ["domain"]=> string(10) "google.com" }
Error handling
Every error throws exception Chartbeat\Exception.
try { // set invalid key and try to get data $cb->setApiKey('invalidapikey'); $cb->getMonthlyMaxPeople(); } catch (Chartbeat\Exception $ex) { echo "Caught exception: " . $ex->getMessage(); // will output "Caught exception: Chartbeat API error. Message: No Access, Code: 403" }
Testing
You can test this library by running example.php with:
./example.php <your host> <your API key>
This will output monthly max people your site
统计信息
- 总下载量: 9.52k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2012-10-28