0

私は現在、Uservoice フォーラムと提案を追加したい Facebook アプリを開発しています。

API を使用して、既に作成されているフォーラムと提案を取り込むことができましたが、ユーザーがフォーラム内で提案を作成/投票できるようにしたいと考えています。UserVoice のドキュメントには、Oauth を使用して PHP でアプリを設定する例が示されていません。

私は OAuth のトピックに不慣れで、この件についていくつか読んで、OAuth の仕組みの基本を理解していますが、PHP でリクエストを実装する方法がわかりません。どんな助けでもいただければ幸いです

ありがとう

4

1 に答える 1

2

最近、新しい 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");
    }
?>

composer.json に uservoice/uservoice を必ず含めてください。Composer を使用しない場合は、GitHubからプロジェクトを複製してください。

"require": {
    "uservoice/uservoice": "0.0.6"
}

OAuthmcrypt PHP5 拡張機能が必要です。

その他の例とインストール手順: http://developer.uservoice.com/docs/api/php-sdk/

于 2012-11-06T20:34:32.533 に答える