带有授权标头的GET请求(带有httparty或faraday)

时间:2020-01-26 14:20:35

标签: ruby httparty faraday

我正在尝试使用twitter api来获取一些数据(由于https://github.com/sferik/twitter不再被更新,因此我需要的某些字段被忽略了)

我可以让Postman处理我定义的字段,即Oauth 1.0的授权,消费者密钥和消费者秘密。

enter image description here

我的问题:如何在Ruby中定义这些参数?使用HTTParty或Faraday很好。

我只能得到这样的东西

  url = 'https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=balajis&exclude_replies=true&include_rts=false&count=100&tweet_mode=extended&trim_user=true'
  xml = HTTParty.get(url,
                     headers: {"Authorization" => "???"}).body

在四处搜寻之后,我只能找到使用oauth 2.0的示例(例如https://github.com/lostisland/faraday_middleware/wiki/Oauth中的内容)


更新

Postmand中的代码没有任何授权。我有什么想念吗?

enter image description here

1 个答案:

答案 0 :(得分:0)

在生成的代码段窗口中,单击设置图标并启用第一个选项(包括临时标题)