#json #ruby #instagram #httparty
#json #ruby #Instagram #httparty
Вопрос:
Пытаюсь использовать API Instagram, и content-type
вместо «application / json» возвращается «text / html». Затем у меня возникла проблема с принудительным введением этого 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"]}
Как я могу перевести это в правильный формат as json
или a hash
? Да, я просмотрел другие сообщения, и у них нет ответов.
Ответ №1:
Оказывается, им нужна авторизация OAuth для простых GET
s, подобных этому. Итак, это повтор.