2013-08-17 70 views
0

我正在通過API寫入Uservoice文章。我使用以下代碼編寫: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']}" 

This works。但是,當我想要做一個更新即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)的作品,但更新不。

回答

0

不要忘記以管理員(或所有者)的身份登錄。

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/