【问题标题】:Uservoice updating an article doesn't workUservoice 更新文章不起作用
【发布时间】:2013-08-17 05:54:34
【问题描述】:

我正在通过 API 写 Uservoice 文章。我使用以下代码编写:

    data = {
      :article =>
        {
          :question => question_name,
          :answer_html => html,
          :published => true
        }
    }

    site = "http://myapp.uservoice.com"

    puts "Remote site = #{site}"
    consumer = OAuth::Consumer.new(APP_CONFIG["uservoice"]["key"],
      APP_CONFIG["uservoice"]["secret"],
      {:site => site})

    accesstoken = OAuth::AccessToken.new(consumer,
     user.helpdesk["uservoice"]["oauth_token"],
     user.helpdesk["uservoice"]["oauth_token_secret"])

    response = JSON.parse(accesstoken.post("/api/v1/articles.json", data).body)
    flow.uservoice_id = response['article']['id']
    flow.save!
    puts "Save successful at #{response['article']['url']}"

这行得通。但是当我想做更新时,即PUT

    response = JSON.parse(accesstoken.put("/api/v1/articles/#{article_id}.json", data))

我得到一个

{"errors"=>{"type"=>"unauthorized", "message"=>"Admin required: Not signed or not admin. Unverified; Signature verification failed; User not signed: oauthenticate failed"}}

作为回应。我也是管理员。写入 (POST) 有效,但更新无效。

【问题讨论】:

    标签: ruby uservoice


    【解决方案1】:

    不要忘记以管理员(或所有者)身份登录。

    accesstoken.login_as_owner do |owner|
      posted_response = owner.post("/api/v1/articles/#{article_id}.json", data)
    end
    

    查看https://developer.uservoice.com/docs/api/ruby-sdk/上的“获取帐户所有者的访问令牌并发布回复”部分

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-06
      • 1970-01-01
      • 1970-01-01
      • 2013-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多