marcelomx / zemanta
此包已被废弃,不再维护。未建议替代包。
Zemanta PHP API
dev-master
2013-12-24 19:45 UTC
Requires
- php: >= 5.3.3
- guzzle/guzzle: v3.7.4
Requires (Dev)
- phpunit/phpunit: 3.7
This package is not auto-updated.
Last update: 2016-12-14 22:47:57 UTC
README
有关API的更多信息以及获取API密钥,请参阅 http://developer.zemanta.com
用法
use Zemanta\Zemanta;
$zemanta = new Zemanta('your_api_key');
$params = array(
'method' => 'zemanta.suggest',
'text' => 'Your text'
);
$suggest = $zemanta->api($params);
api
方法也支持将API method
参数作为第一个参数,并将可选API参数作为数组作为第二个或第三个参数。
$params = array('format' => 'json');
$zemanta->api('zemanta.suggest', $params);
// or with text
$zemanta->api('zemanta.suggest', 'Your text', $params);
要使用 suggest
和 suggestMarkup
API方法,可以在Zemanta实例上使用直接方法。
// Suggest
$response = $zemanta->suggest('Your text');
// Markup
$response = $zemanta->suggestMarkup('Your text');
要使用原始参数进行请求,请使用带有参数数组的 request
方法。
$args = array(
'method' => 'zemanta.suggest',
'text' => 'Your text',
'format' => 'json'
)
$response = $zemanta->request($args);
API支持json
、wnjson
、xml
和rdfxml
作为输出格式。如果未提供格式参数,则默认使用xml
格式。
api
或 request
方法返回一个 Zemanta\Response
实例。要打印或解析原始响应体,可以使用 getBody
方法。
echo $response->getBody();
// Zemanta\Response supports __toString() magic method, so you could print it direct.
echo $response;
要将响应导出为数组,请对 json
格式使用。
$array = $response->toArray();