首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过UserVoice API使用OAuth

通过UserVoice API使用OAuth
EN

Stack Overflow用户
提问于 2012-02-21 19:56:54
回答 1查看 591关注 0票数 0

我目前正在开发一个Facebook应用程序,我希望在其中添加用户语音论坛和建议

我已经设法使用API来拉入已经创建的论坛和建议,但我现在希望允许用户在论坛内创建/投票建议。UserVoice上的文档没有提供使用Oauth在PHP中设置应用程序的示例。

我是一个新的OAuth主题的新手,已经围绕这个主题做了一些阅读,理解了OAuth如何工作的基本原理,但我只是不知道如何用PHP语言实现请求。任何帮助都将不胜感激

谢谢

EN

回答 1

Stack Overflow用户

发布于 2012-11-07 04:34:33

我们最近刚刚开发了一个新的UserVoice PHP library。下面的示例在您的UserVoice帐户中找到第一个论坛,以user@example.com的身份发布新的建议,然后使用库将同一建议中的用户投票数更新为2:

代码语言:javascript
复制
<?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中包含用户语音/用户语音。如果你不使用Composer,只需从GitHub克隆项目即可。

代码语言:javascript
复制
"require": {
    "uservoice/uservoice": "0.0.6"
}

您需要OAuthmcrypt PHP5扩展。

更多示例和安装说明:http://developer.uservoice.com/docs/api/php-sdk/

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9377183

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档