簡體   English   中英

Ruby Instagram API 內容類型錯誤

[英]Ruby Instagram API content-type Wrong

嘗試使用 Instagram 的 API,我得到的content-type是“text/html”而不是“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的正確格式? 是的,我看過其他帖子,但他們沒有答案。

結果他們需要 OAuth 授權來獲得像這樣的簡單GET 所以這是重做。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM