是的,可以将Instagram帖子和帖子上的评论保存到您的域中。以下是实现这一目标的基本概念和方法:
/users/{user-id}/media/recent
获取帖子,使用/media/{media-id}/comments
获取评论。import requests
from requests_oauthlib import OAuth1
# 设置OAuth认证信息
client_id = 'YOUR_CLIENT_ID'
client_secret = 'YOUR_CLIENT_SECRET'
access_token = 'USER_ACCESS_TOKEN'
access_token_secret = 'USER_ACCESS_TOKEN_SECRET'
auth = OAuth1(client_id, client_secret, access_token, access_token_secret)
# 获取用户帖子
response = requests.get('https://api.instagram.com/v1/users/self/media/recent/', auth=auth)
posts = response.json()['data']
for post in posts:
post_id = post['id']
# 获取帖子评论
comments_response = requests.get(f'https://api.instagram.com/v1/media/{post_id}/comments', auth=auth)
comments = comments_response.json()['data']
# 保存帖子和评论到数据库(此处省略具体实现)
通过上述方法,您可以有效地将Instagram帖子和评论保存到您的域中,并进行进一步的分析和利用。
领取专属 10元无门槛券
手把手带您无忧上云