Недавно мы работали над новой библиотекой UserVoice PHP . Следующий пример находит первый форум в вашей учетной записи UserVoice, публикует новое предложение как user@example.com, а затем обновляет счетчик голосов пользователей до 2 в том же предложении с использованием библиотеки:
<?php
require_once('vendor/autoload.php');
try {
// Create a new UserVoice client for subdomain.uservoice.com
$client = new \UserVoice\Client('subdomain', 'API KEY', 'API SECRET');
// Get access token for user@example.com
$token = $client->login_as('user@example.com');
// Get the first accessible forum's id
$forums = $token->get_collection('/api/v1/forums', array('limit' => 1));
$forum_id = $forums[0]['id'];
$result = $token->post("/api/v1/forums/$forum_id/suggestions", array(
'suggestion' => array(
'title' => 'Move the green navbar to right',
'text' => 'Much better place for the green navbar',
'votes' => 1
)
));
$suggestion_id = $result['suggestion']['id'];
$suggestion_url = $result['suggestion']['url'];
print("See the suggestion at: $suggestion_url\n");
// Change to two instead of one votes.
$token->post("/api/v1/forums/$forum_id/suggestions/$suggestion_id/votes",
array('to' => 2 )
);
} catch (\UserVoice\APIError $e) {
print("Error: $e\n");
}
?>
Обязательно включите uservoice / uservoice в ваш composer.json. Если вы не используете Composer, просто клонируйте проект из GitHub .
"require": {
"uservoice/uservoice": "0.0.6"
}
Вам нужны OAuth и mcrypt PHP5 расширения.
Дополнительные примеры и инструкции по установке: http://developer.uservoice.com/docs/api/php-sdk/