2012-02-21 78 views
0

我目前正在開發Facebook應用中,我想補充UserVoice的論壇和建議使用OAuth與UserVoice的API

我已成功地使用API​​在已創建的論壇和建議來拉,但我現在想讓用戶在論壇中創建/投票建議。 UserVoice的文檔沒有給出使用Oauth在PHP中設置應用程序的示例。

我是新的OAuth主題,已經做了一些關於主題的閱讀,瞭解OAuth如何工作的基礎知識,但我不知道如何在PHP中實現請求。任何幫助,將不勝感激

感謝

+0

能否請您給的如何檢索在PHP中UserVoice的信息的樣本? – Seeker 2012-09-03 08:22:41

回答

2

我們剛剛上了一個新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" 
} 

你需要OAuthmcrypt PHP5擴展。

更多的例子和安裝說明:http://developer.uservoice.com/docs/api/php-sdk/