能否通过Instagram API获取过去指定时间点(如7/14天前)的粉丝数?
Instagram API获取历史粉丝数的解决方案
核心结论
Instagram官方提供的Graph API(含Basic Display API)没有直接获取指定历史时间点(比如7天或14天前)粉丝总数的接口,官方接口仅能返回当前粉丝数,或Insights中的粉丝增长趋势数据(而非某一天的累计粉丝数)。
可行技术方案
- 自行定期采集并存储数据
这是最可靠的解决方案:通过合法API定时获取当前粉丝数,将数据与时间戳一起存入自有数据库,后续查询历史数据直接从数据库读取即可。- 适用条件:账号为商业/创作者账号(可访问Insights接口)或个人账号(仅能获取当前粉丝数),且拥有合法的API访问权限。
- 实现思路:
- 定时调用API获取当前粉丝数:使用
/{user-id}/insights接口(商业/创作者账号)或Basic Display API的用户信息接口获取粉丝数。 - 将粉丝数与当前时间戳写入数据库(如MySQL、MongoDB)。
- 查询历史数据时,根据时间戳筛选出7天或14天前的记录。
- 定时调用API获取当前粉丝数:使用
- 伪代码示例:
import requests import datetime import pymongo # 获取当前粉丝数(商业/创作者账号) def fetch_follower_count(access_token, user_id): api_url = f"https://graph.facebook.com/v18.0/{user_id}/insights?metric=follower_count&access_token={access_token}" res = requests.get(api_url) data = res.json() return data['data'][0]['values'][0]['value'] if data.get('data') else None # 存储数据到MongoDB def store_follower_data(followers): client = pymongo.MongoClient("your_database_uri") db = client["ig_data"] db.follower_history.insert_one({ "count": followers, "recorded_at": datetime.datetime.utcnow() }) # 执行采集(可通过cron/云函数定时触发) if __name__ == "__main__": ACCESS_TOKEN = "your_valid_access_token" USER_ID = "your_ig_user_id" current_followers = fetch_follower_count(ACCESS_TOKEN, USER_ID) if current_followers: store_follower_data(current_followers)
- 合规第三方工具辅助
若不想自行开发,可使用合规的社交媒体分析工具(需确保工具遵守Instagram API条款),这类工具通常会持续抓取并存储账号的历史粉丝数据,可直接查询指定时间点的数值。
注意事项
- 商业/创作者账号需通过Instagram Graph API申请对应权限,个人账号仅能通过Basic Display API获取当前粉丝数。
- 严格遵守Instagram API的调用频率限制,避免触发接口封禁。
内容的提问来源于stack exchange,提问作者sub
相关产品推荐
相关产品推荐

