【问题标题】:Ruby Instagram API content-type WrongRuby Instagram API 内容类型错误
【发布时间】:2021-04-04 17:36:17
【问题描述】:

尝试使用 Instagram 的 API 时,我收到了“text/html”的content-type,而不是“application/json”。然后,我在将其强制转换为 json 时遇到问题。

require 'httparty'
rec = HTTParty.get('https://www.instagram.com/web/search/topsearch/?query=prawncocktail')
puts rec.headers    # content-type is text/html and should be 'application/json'

不知道如何让它工作。即使将httparty 参数更改为包含“format: :json”也不起作用。以下是请求的一些标头:

{"content-type"=>["text/html; charset=utf-8"],
     "ig-set-password-encryption-web-key-id"=>["108"],
     "ig-set-password-encryption-web-pub-key"=>["ae57c2c94c4afb24eeda9cd759faeeb034086d0ebe60e90123baed5e38c3304f"],
     "ig-set-password-encryption-web-key-version"=>["10"],
     "vary"=>["Cookie,
     Accept-Language,
     Accept-Encoding"],
     "last-modified"=>["Sun,
     27 Dec 2020 18:13:33 GMT"],
     "expires"=>["Sat,
     01 Jan 2000 00:00:00 GMT"],
     "cache-control"=>["private,
     no-cache,
     no-store,
     must-revalidate"],
     "content-language"=>["en"],
     "date"=>["Sun,
     27 Dec 2020 18:13:33 GMT"],
     "strict-transport-security"=>["max-age=31536000"],
     "pragma"=>["no-cache"],
     "x-frame-options"=>["SAMEORIGIN"],
     "content-security-policy"=>["report-uri https://www.instagram.com/security/csp_report/; default-src 'self' https://www.instagram.com; img-src data: blob: https://*.fbcdn.net https://*.instagram.com https://*.cdninstagram.com https://*.facebook.com https://*.giphy.com; font-src data: https://*.fbcdn.net https://*.instagram.com https://*.cdninstagram.com; media-src 'self' blob: https://www.instagram.com https://*.cdninstagram.com https://*.fbcdn.net; manifest-src 'self' https://www.instagram.com; script-src 'self' https://instagram.com https://www.instagram.com https://*.www.instagram.com https://*.cdninstagram.com wss://www.instagram.com https://*.facebook.com https://*.fbcdn.net https://*.facebook.net 'unsafe-inline' 'unsafe-eval' blob:; style-src 'self' https://*.www.instagram.com https://www.instagram.com 'unsafe-inline'; connect-src 'self' https://instagram.com https://www.instagram.com https://*.www.instagram.com https://graph.instagram.com https://*.graph.instagram.com https://*.cdninstagram.com https://api.instagram.com https://i.instagram.com wss://www.instagram.com wss://edge-chat.instagram.com https://*.facebook.com https://*.fbcdn.net https://*.facebook.net chrome-extension://boadgeojelhgndaghljhdicfkmllpafd blob:; worker-src 'self' blob: https://www.instagram.com; frame-src 'self' https://instagram.com https://www.instagram.com https://*.instagram.com https://staticxx.facebook.com https://www.facebook.com https://web.facebook.com https://connect.facebook.net https://m.facebook.com; object-src 'none'; upgrade-insecure-requests"],
     "x-content-type-options"=>["nosniff"],
     "x-xss-protection"=>["0"],
     "x-aed"=>["36"],
     "access-control-expose-headers"=>["X-IG-Set-WWW-Claim"],
     "set-cookie"=>["sessionid=\"\"; Domain=instagram.com; expires=Thu,
     01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/",
     "sessionid=\"\"; Domain=.instagram.com; expires=Thu,
     01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/",
     "sessionid=\"\"; Domain=i.instagram.com; expires=Thu,
     01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/",
     "sessionid=\"\"; Domain=.i.instagram.com; expires=Thu,
     01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/",
     "sessionid=\"\"; Domain=www.instagram.com; expires=Thu,
     01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/",
     "sessionid=\"\"; Domain=.www.instagram.com; expires=Thu,
     01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/",
     "sessionid=\"\"; expires=Thu,
     01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/",
     "csrftoken=vjVhuWVAUCvnmYwhc6H4Z7DTgKvrKTX8; Domain=.instagram.com; expires=Sun,
     26-Dec-2021 18:13:33 GMT; Max-Age=31449600; Path=/; Secure",
     "__to_be_deleted__instagram.comMax-Age=\"\"; Domain=instagram.com; expires=Thu,
     01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"],
     "x-fb-trip-id"=>["1679558926"],
     "alt-svc"=>["h3-29=\":443\"; ma=3600,
    h3-27=\":443\"; ma=3600"],
     "connection"=>["close"],
     "content-length"=>["12859"]}

我怎样才能将其转换为jsonhash 的正确格式?是的,我看过其他帖子,但没有答案。

【问题讨论】:

    标签: json ruby instagram httparty


    【解决方案1】:

    原来他们需要 OAuth 授权才能获得像这样的简单 GETs。所以这是重做。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-28
      • 2017-08-15
      相关资源
      最近更新 更多