Problem with getting Instagram hashtag json without api into google sheets

早过忘川 提交于 2020-11-29 03:39:32

问题


I'm trying to get a hashtag JSON back from Instagram to google sheets. I get the JSON if I put the URL in a browser but not using google sheets script (it used to work in the past).

This is my code:

//Trying to bring back json from instagram
  var tag = 'trivia';
  var url = "https://www.instagram.com/explore/tags/"+tag+"/?__a=1";
  var response = UrlFetchApp.fetch(url).getContentText();
  Logger.log(response);

I get this:

[20-06-21 12:01:29:962 IDT] <!DOCTYPE html>
<html lang="en" class="no-js not-logged-in client-root">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">

        <title>
Login • Instagram
</title>...

instead of this (when I put the same url in a browser- https://www.instagram.com/explore/tags/trivia/?__a=1): which is what I actually need btw to get in google sheets.

{"graphql":{"hashtag":{"id":"17841563248119719","name":"trivia","allow_following":true,"is_following":false,"is_top_media_only":false,"profile_pic_url":"https://instagram.fsdv3-1.fna.fbcdn.net/v/t51.2885-15/e15/s150x150/103649320_140557634281171_6362475220936910641_n.jpg?_nc_ht=instagram.fsdv3-1.fna.fbcdn.net&_nc_cat=107&_nc_ohc=QVtIBqOksWoAX9m12su&oh=fcaa18b44873d0b30d46e6c3369535c1&oe=5F1930BA","edge_hashtag_to_media":{"count":1284222,"page_info":{"has_next_page":true,"end_cursor":"QVFBdkxFeVcxRkFtVjVPaWdNZDhQeHRobHo0dlVfdjhtekVwazRTcjBIOXlwb0NqRndwaDZPZ195ZFdRd2t5RjU1OThiVExXLV9iLU5YUlkwSk5BUmE2LQ=="},"edges":[{"node":{"comments_disabled":false,"__typename":"GraphSidecar","id":"2336312505423207882","edge_media_to_caption":{"edges":[{"node":{"text":"Information about the movie:\n1. Director:\u00a0James Cameron\n2. Box office:\u00a0279 crores\u00a0\n3. Budget:\u00a023.7 crores\u00a0\n4. Film series:\u00a0Avatar Series\n5. IMDB: 7.8/10\n#avatar\u00a0#no.1movie\u00a0#jamescameron\u00a0#trivia\u00a0#facts#didyouknow\u00a0#information\u00a0#actors\u00a0#like\u00a0#follow#horrormovies\u00a0#fashion\u00a0#instamovies\u00a0#entertainment#moviereview\u00a0#bluray\u00a0#series\u00a0#photooftheday\u00a0#dvd\u00a0#bhfyp#marvel\u00a0#moviestar\u00a0#acting\u00a0#action\u00a0#movietime\u00a0#filmes#peliculas\u00a0#theatre\u00a0#oscars\u00a0#moviequotes"}}]},"shortcode":"CBsP9hqDZ3K","edge_media_to_comment":{"count":0},"taken_at_timestamp":1592730175,"dimensions":{"height":1080,"width":1080},"display_url":"https://instagram.fsdv3-1.fna.fbcdn.net/v/t51.2885-15/e35/104434100_280716426462541_3340933663299493770_n.jpg?_nc_ht=instagram.fsdv3-1.fna.fbcdn.net&_nc_cat=101&_nc_ohc=wYDWOpszIK0AX8sTi3N&oh=980538cb2e588f4467f0769ebae0c30e&oe=5F187460","edge_liked_by":{"count":6},"edge_media_preview_like":{"count":6},"owner":{"id":"37570480318"},"thumbnail_src":"https://instagram.fsdv3-1.fna.fbcdn.net/v/t51.2885-15/sh0.08/e35/s640x640/104434100_280716426462541_3340933663299493770_n.jpg?_nc_ht=instagram.fsdv3-1.fna.fbcdn.net&_nc_cat=101&_nc_ohc=wYDWOpszIK0AX8sTi3N&oh=97756e538cc662343493f9c6588fdfe2&oe=5F17CA66","thumbnail_resources":[{"src":"https://instagram.fsdv3-1.fna.

please help and please don't suggest getting an api which is a nightmare - I don't need that many queries anyway


回答1:


There are two things that you are using.

  1. browser
  2. is google sheets script.

The reason why you are getting error is Instagram bot which actually tracks your IP when you make a request to it. When you are logged into your browser and request this https://www.instagram.com/explore/tags/"+tag+"/?__a=1 then you will always get data without being blocked.

But now, after the deprecation of old Instagram developer tool the rate limit of endpoints have reduced to 200 per hour. You get blocked because you cross the limit and Instagram bot takes time to reset your limit again.

It may take 2-3 days or more depending on frequency of getting blocked. Yhe solution is if you properly apply session and cookies to request headers then it will surely help you.



来源:https://stackoverflow.com/questions/62496539/problem-with-getting-instagram-hashtag-json-without-api-into-google-sheets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!