We have just recently worked on a new UserVoice PHP library. The following example finds the first forum in your UserVoice account, posts a new suggestion as user@example.com and then updates user vote count to 2 in the same suggestion using the library:
<?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");
}
?>
Be sure to include uservoice/uservoice in your composer.json. If you don't use Composer, just clone the project from GitHub.
"require": {
"uservoice/uservoice": "0.0.6"
}
You need OAuth and mcrypt PHP5 extensions.
More examples and installation instructions: http://developer.uservoice.com/docs/api/php-sdk/