awelters/hatebase

Hatebase 是一个用于消费 Hatebase API 的 PHP HTTP 客户端库

dev-master 2016-10-12 20:22 UTC

This package is not auto-updated.

Last update: 2024-09-28 14:52:28 UTC


README

hatebase.org API v3.0 的简单 PHP 包装器 hatebase.org API

如何使用

  1. 获取hatebase API 密钥
  2. 安装composer
  3. 创建一个新的 composer.json 文件,将 awelters/hatebase 作为依赖项(或添加到项目中现有的 composer.json 文件中)
{
    "require": {
    	"awelters/hatebase": "dev-master"
    }
}
  1. 使用 composer 安装依赖项
  2. 尝试一下。以下 PHP 脚本可以通过简单地添加您的 Hatebase API 密钥作为起点使用
<?php
/**
* Andrew's Hatebase script : Simple script to retrieve results from Hatebase API
*
* @category Awesomeness
* @date 3/03/2014
* @author Andrew Welters <awelters@hugmehugyou.org>
* @license https://open-source.org.cn/licenses/MIT The MIT License
* @link http://www.hatebase.org/connect_api
* @link https://github.com/awelters/hatebase
*/
ini_set('display_errors', 1);
header('Content-type: application/json');

require_once __DIR__ . '/vendor/autoload.php'; // Autoload files using Composer autoload

use Hatebase\HatebaseAPI;

$settings = array(
    'key' => '',
    'version' => '3' //optional
);
$hatebase = new HatebaseAPI($settings);

//See http://www.hatebase.org/connect_api for filter options
$filters = array('about_nationality' => '1', 'language' => 'eng');
$output = 'json'; //either 'xml' or 'json', 'xml' is faster
$query_type = 'sightings'; //either 'vocabulary' or 'sightings'

try {
	$result = $hatebase->performRequest($filters, $output, $query_type);
	print_r($result);
}
catch(Exception $e) {
	echo 'Error: '.$e;
}