我們剛剛上了一個新UserVoice的PHP library工作。下面的例子中找到的第一個論壇,您的UserVoice帳戶,發佈一個新的建議爲[email protected],然後更新用戶投票使用的庫計數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 [email protected]
$token = $client->login_as('[email protected]');
// 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/
能否請您給的如何檢索在PHP中UserVoice的信息的樣本? – Seeker 2012-09-03 08:22:41