我之前使用Instagram API按标签,位置等访问公共图片。我创建了一个新应用程序并检索了access_token
,但这些公共媒体搜索不再返回任何数据。但是,它们返回200种状态。
在文档中,它表示"不接受的应用程序"对于这些搜索所需的public_content
范围。因此,似乎Instagram API已被弃用。
这对我来说没有任何意义(这就是我在这里发布的原因),因为这些类型的搜索是许多应用程序和服务的核心。我还对这些请求如何仍然返回200条回复感到困惑。
我想知道是否还有其他方法可以访问Instagram上的公共内容,例如使用Facebook API。 Instagram是否希望完全阻止开发人员访问公共照片?或者这只是将Instagram API功能移植到另一个API,如Facebook?
答案 0 :(得分:0)
如果您无法使用API,可以尝试废弃HTML。
您可以通过链接https://www.instagram.com/explore/tags/[TAG]/
获取所需标记的html例如
curl https://www.instagram.com/explore/tags/telegram/
然后你必须找到从“< script type =”text / javascript“> window._sharedData =”开始的刺痛 任何流行的语言都可以轻松解析JSON。
根据这些数据,您可以获得帖子的“短代码”列表。例如“BfLErJ_hzak”
接下来,您可以通过链接https://www.instagram.com/p/[SHORTCODE]/?__a=1
获取详细信息EG。
curl https://www.instagram.com/p/BfLErJ_hzak/?__a=1
它返回JSON数据。见例子
{"graphql":{"shortcode_media":{"__typename":"GraphImage","id":"1714484640997652132","shortcode":"BfLErJ_hzak","dimensions":{"height":1080,"width":1080},"gating_info":null,"media_preview":"ACoqamHCl0YsgAyQeMc//qp8DFiXPUmrTTbarwgmUlfu8HHHGaHqES0yqT6ZH61Pa9vp/SlQIi7Rg4/X/P6Utuc84K4B4NG2gbkyj7v5/pQZcEinL1HsP8KhKE8+tMRkzHiqQcJzz/jVi4gOMpwfaqRmLrsfr09zTA3YYzjcR+A5/wA/hVvB2lhxxkf4H61BZy70GRgjj644zVxOmDUgCtnnvipQABiqhyhyPX9Kk88e1MCo6dR3rKeLKhx+PtW0/QfQVmwnlx7mmI0IYR5akcHAqfdtOTTLf/Vr9KbLUjJnCnv15qgUWi2JKHPPOP50/NNAf//Z","display_url":"https://instagram.fhel3-1.fna.fbcdn.net/vp/d44e27e253f499ab84bd5944c8a93313/5B044F81/t51.2885-15/e35/27581038_2488346268057255_6612776414812831744_n.jpg","display_resources":[{"src":"https://instagram.fhel3-1.fna.fbcdn.net/vp/0e2d4f8e3b780cc4fba827e2afbcd7bd/5B180DAB/t51.2885-15/s640x640/sh0.08/e35/27581038_2488346268057255_6612776414812831744_n.jpg","config_width":640,"config_height":640},{"src":"https://instagram.fhel3-1.fna.fbcdn.net/vp/2d7cba2b057809aa589ab589baed3aff/5B087C45/t51.2885-15/s750x750/sh0.08/e35/27581038_2488346268057255_6612776414812831744_n.jpg","config_width":750,"config_height":750},{"src":"https://instagram.fhel3-1.fna.fbcdn.net/vp/d44e27e253f499ab84bd5944c8a93313/5B044F81/t51.2885-15/e35/27581038_2488346268057255_6612776414812831744_n.jpg","config_width":1080,"config_height":1080}],"is_video":false,"should_log_client_event":false,"tracking_token":"eyJ2ZXJzaW9uIjo1LCJwYXlsb2FkIjp7ImlzX2FuYWx5dGljc190cmFja2VkIjpmYWxzZSwidXVpZCI6IjdiZjJhOGI4MTc5YzRmMTViYWZmOGViYjg4N2RkOWZhMTcxNDQ4NDY0MDk5NzY1MjEzMiJ9LCJzaWduYXR1cmUiOiIifQ==","edge_media_to_tagged_user":{"edges":[]},"edge_media_to_caption":{"edges":[{"node":{"text":"Cuando se te pegan las mantas \ud83d\ude48\ud83d\ude48\ud83d\ude48\n.\n10,90\u20ac\n.\nhttp://s.click.aliexpress.com/e/EaEYFaE\n\nFACEBOOK.COM/ROPATEANDO\nBLOG.ROPATEANDO.COM\n.\n#mantabebe#ropateando #elarmarioderopateando #telegram #pic #picoftheday #outfit #outfitoftheday #outfitpost #ropa #instame #instalike #instalove #instalook #fashion #moda #instablogger #ootd #love #instagood #me #cute #like #influencer #beautiful #style #streetstyle"}}]},"caption_is_edited":true,"edge_media_to_comment":{"count":2,"page_info":{"has_next_page":false,"end_cursor":null},"edges":[{"node":{"id":"17850908371233214","text":"Link","created_at":1518602595,"owner":{"id":"55206905","profile_pic_url":"https://instagram.fhel3-1.fna.fbcdn.net/vp/0f2d694caef7809255bd21e18579ebf3/5B2176B2/t51.2885-19/s150x150/22802830_358422461266066_4296876623711436800_n.jpg","username":"lorenacuaja"}}},{"node":{"id":"17924024554016118","text":"Enviado","created_at":1518602616,"owner":{"id":"2096327952","profile_pic_url":"https://instagram.fhel3-1.fna.fbcdn.net/vp/b142448b7225a12c25a81c4e4f84a577/5B0BFE21/t51.2885-19/s150x150/11930847_519140961600089_515209800_a.jpg","username":"ropateando"}}}]},"comments_disabled":false,"taken_at_timestamp":1518602517,"edge_media_preview_like":{"count":19,"edges":[{"node":{"id":"330280392","profile_pic_url":"https://instagram.fhel3-1.fna.fbcdn.net/vp/ff423c2bc927ec317701338712461b28/5B246257/t51.2885-19/s150x150/26071831_1616366641789125_3093631880650555392_n.jpg","username":"vlimamart"}},{"node":{"id":"5979047553","profile_pic_url":"https://instagram.fhel3-1.fna.fbcdn.net/vp/f4d1635630b571fb16b2b1f1cf99fd8e/5B039B10/t51.2885-19/s150x150/21227380_116088969094159_5157150429842243584_a.jpg","username":"dochylos"}},{"node":{"id":"226729325","profile_pic_url":"https://instagram.fhel3-1.fna.fbcdn.net/vp/8f76c54bb62f45ec33fe5e8b0fa2b733/5B234418/t51.2885-19/11428696_136540733352298_2103764682_a.jpg","username":"elsagcallejo"}},{"node":{"id":"2958399052","profile_pic_url":"https://instagram.fhel3-1.fna.fbcdn.net/vp/2ca058e070ce56861ae48fbf2c8ea931/5B1D2C9B/t51.2885-19/s150x150/19429360_320564085053737_4974100564364230656_a.jpg","username":"suraj_sk2"}},{"node":{"id":"1375472655","profile_pic_url":"https://instagram.fhel3-1.fna.fbcdn.net/vp/a3fd8350cb45401d0ab50aad95ef427f/5B111BD7/t51.2885-19/s150x150/26151195_2090241727875639_7471255521614364672_n.jpg","username":"alandashenka"}},{"node":{"id":"265784569","profile_pic_url":"https://instagram.fhel3-1.fna.fbcdn.net/vp/4b062db4cbf5bb2a50fbbffe2d6109b9/5B253FE0/t51.2885-19/s150x150/25017909_2061467437421348_4184874695654375424_n.jpg","username":"themayorsstatement"}},{"node":{"id":"6883303908","profile_pic_url":"https://instagram.fhel3-1.fna.fbcdn.net/vp/b4577832af28080a9607edcb758799cc/5B1A8203/t51.2885-19/s150x150/25037105_1997130850508677_1213534002938380288_n.jpg","username":"real247fitness"}},{"node":{"id":"1476593644","profile_pic_url":"https://instagram.fhel3-1.fna.fbcdn.net/vp/69d2a696339d3e64a6d6449cd36d10b9/5B151E06/t51.2885-19/s150x150/12139598_1056916654326731_785215976_a.jpg","username":"bbstylemiami"}},{"node":{"id":"5373895103","profile_pic_url":"https://instagram.fhel3-1.fna.fbcdn.net/vp/e4d101a7b7823862ff5ea09b9ca64db0/5B1C6515/t51.2885-19/s150x150/18443920_1839735143016586_6944955834094845952_a.jpg","username":"iambrokool"}},{"node":{"id":"345451524","profile_pic_url":"https://instagram.fhel3-1.fna.fbcdn.net/vp/0b4a2bceb2eaa1efd841874df94367e0/5B0B0207/t51.2885-19/11821658_877787485604500_693329869_a.jpg","username":"pleasefashionofficial"}}]},"edge_media_to_sponsor_user":{"edges":[]},"location":null,"viewer_has_liked":false,"viewer_has_saved":false,"viewer_has_saved_to_collection":false,"owner":{"id":"2096327952","profile_pic_url":"https://instagram.fhel3-1.fna.fbcdn.net/vp/b142448b7225a12c25a81c4e4f84a577/5B0BFE21/t51.2885-19/s150x150/11930847_519140961600089_515209800_a.jpg","username":"ropateando","blocked_by_viewer":false,"followed_by_viewer":false,"full_name":"RopaTeando","has_blocked_viewer":false,"is_private":false,"is_unpublished":false,"is_verified":false,"requested_by_viewer":false},"is_ad":false,"edge_web_media_to_related_media":{"edges":[]}}}}a
如您所见,它包含图片,标题,用户信息,用户标记,评论......等等。
答案 1 :(得分:0)
根据您的问题,我会看InstaPy。它有一个简单的API,它使用Selenium,一个浏览器自动化框架,因此您可以避免API限制。
安装InstaPy:
$ git clone https://github.com/timgrossmann/InstaPy.git
$ cd InstaPy
$ pip install .
# or
$ python setup.py install
创建一个脚本:
# scraper.py
from instapy import InstaPy
insta_username = ''
insta_password = ''
# if you want to run this script on a server,
# simply add nogui=True to the InstaPy() constructor
session = InstaPy(username=insta_username, password=insta_password)
session.login()
# set up all the settings
session.set_upper_follower_count(limit=2500)
session.set_do_comment(True, percentage=10)
session.set_comments(['aMEIzing!', 'So much fun!!', 'Nicey!'])
session.set_dont_include(['friend1', 'friend2', 'friend3'])
session.set_dont_like(['pizza', 'girl'])
# do the actual liking
session.like_by_tags(['natgeo', 'world'], amount=100)
# end the bot session
session.end()
运行脚本:
$ python scraper.py
媒体:
如果您不熟悉Python,请查看Puppeteer。
Puppeteer是一个Node库,它提供了一个高级API,通过DevTools协议控制无头Chrome或Chromium。它也可以配置为使用完整(非无头)Chrome或Chromium。
安装Puppeteer:
npm i --save puppeteer
创建一个脚本:
// scraper.js
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://instagram.com');
// Take a screen shot
await page.screenshot({path: 'example.png'});
await browser.close();
})();
运行脚本:
$ node scraper.js
如果您想登录,请按此guide。