Httparty标题

时间:2018-05-30 06:53:19

标签: ruby header instagram httparty

这有什么问题?

HTTParty.get("https://www.instagram.com/#{username}/?__a=1", :headers => {"x-instagram-gis" => Digest::MD5.hexdigest("#{rhx_gis}:/#{username}/")})

如果我使用curl通过--header传递标题做同样的事情,那么它就可以了。

curl "https://www.instagram.com/hossamhossny/" | grep "rhx_gis"

然后我们可以抓取rhx_gis值,然后抓取MD5 "<rhx_gis>:/username/"作为"1ba367317d3c842eb4e940f1d62b29f2:/hossamhossny/",将x-instagram-gis的值设为"2830c5bff8e05b755724df2c6286f2b4"

现在我可以这样做..

curl --header "x-instagram-gis:2830c5bff8e05b755724df2c6286f2b4" "https://www.instagram.com/hossamhossny/?__a=1"

产生所需的输出..

{"logging_page_id":"profilePage_3669759838","show_suggested_profiles":false,"graphql":{"user":{"biography":"","blocked_by_viewer":false,"country_block":false,"external_url":null,"external_url_linkshimmed":null,"edge_followed_by":{"count":222},"followed_by_viewer":false,"edge_follow":{"count":55},"follows_viewer":false,"full_name":"Hossam SAld HossNy","has_blocked_viewer":false,"highlight_reel_count":0,"has_requested_viewer":false,"id":"3669759838","is_private":false,"is_verified":false,"mutual_followers":null,"profile_pic_url":"https://scontent-dfw5-1.cdninstagram.com/vp/6d079f6b5b60323cbfc4442c460d0e52/5BA22630/t51.2885-19/s150x150/13628116_1250649874979851_160235967_a.jpg","profile_pic_url_hd":"https://scontent-dfw5-1.cdninstagram.com/vp/6d079f6b5b60323cbfc4442c460d0e52/5BA22630/t51.2885-19/s150x150/13628116_1250649874979851_160235967_a.jpg","requested_by_viewer":false,"username":"hossamhossny","connected_fb_page":null,"edge_felix_video_timeline":{"count":0,"page_info":{"has_next_page":false,"end_cursor":null},"edges":[]},"edge_owner_to_timeline_media":{"count":0,"page_info":{"has_next_page":false,"end_cursor":null},"edges":[]},"edge_saved_media":{"count":0,"page_info":{"has_next_page":false,"end_cursor":null},"edges":[]},"edge_media_collections":{"count":0,"page_info":{"has_next_page":false,"end_cursor":null},"edges":[]}}}}

切换回HTTParty我试过这个:

HTTParty.get("http://www.instagram.com/#{username}/?__a=1", :headers => {"x-instagram-gis" => "2830c5bff8e05b755724df2c6286f2b4"})

但这也不起作用; 403未经授权的错我的问题是我无法使用HTTParty正确传递标题。

1 个答案:

答案 0 :(得分:0)

带有SSL的网址返回错误,但下面提到的对我有效。

尝试将其与http(不使用https)

一起使用
HTTParty.get("http://www.instagram.com/#{username}/?__a=1", :headers => {"x-instagram-gis" => Digest::MD5.hexdigest("#{rhx_gis}:/#{username}/")})