【问题标题】:GET request with authorization header (with httparty or faraday)带有授权标头的 GET 请求(使用 httparty 或 faraday)
【发布时间】:2020-01-26 14:20:35
【问题描述】:

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

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

我的问题:如何在 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 的代码没有任何授权。我错过了什么吗?

【问题讨论】:

  • 单击屏幕截图中的“代码”链接(直接在“保存”按钮下方)。然后点击Ruby > NET::Http。然后研究如何将 net/http 调用转换为 HTTParty 或 Faraday。
  • @anothermh 你能看到我的更新吗?生成的代码中没有授权。我错过了什么吗?
  • 左侧的“预览请求”给你什么?

标签: ruby httparty faraday


【解决方案1】:

在生成的代码sn-ps窗口中,点击设置图标,启用第一个选项(Include Temporary Header)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-12
    • 1970-01-01
    • 2017-08-07
    • 1970-01-01
    相关资源
    最近更新 更多