开发者

Ruby twitter example - Client must provide a 'status' - Content-Type issue

Got the following error when using Ruby irb to test simple twitter status update ...

#<Net::HTTPForbidden:0x2ca15dc>
<?xml version="1.0" encoding="UTF-8"?>
<hash>
  <request>/statuses/update.xml</request>
  <error>Client must provide a 'status' parameter with a value.</error>
</hash>

Code used was:

twitHeaders = {
  "Content-Type"=>"text/html",
  "Authorization" => "Basic " + Base64::encode64("account:password")
  # where account is twitter account and password is twitter account password
}

def postTwitter statusMsg, headers
  #url = URI.parse( "http://twitter.com/statuses/update.xml" )
  url = URI.parse( "http://twitter.com/statuses/update.json" )
  http = Net::HTTP.new(url.host, url.port)
  resp, data = http.post(url.path, statusMsg , headers)
  return resp, data
end

puts postTwitter( "status=hohoho", twitHeaders )

both .json and .xml effectively produce sam开发者_JS百科e result


Content-Type needed to be application/x-www-form-urlencoded

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜