You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

将Instagram动态脚本改为静态脚本时遇404错误求助

解决Instagram Private API 404 Not Found错误

问题背景

原脚本通过API拉取指定用户的粉丝列表,再调用api.user_info(follower_id)获取用户简介,运行正常。改写后改用静态用户ID/用户名列表,触发HTTP 404错误,报错栈指向api.user_info(follower_id)调用。

可能原因及解决方案

1. 静态用户ID无效或不存在

  • 确认静态列表中的用户ID是Instagram真实存在的有效ID:
    • 可以对比原脚本中正常拉取的粉丝ID,或手动在Instagram网页版搜索该ID验证是否存在;
    • 排查是否存在ID输入错误(多/少数字、格式错误),或目标用户已被删除/封禁。

2. 用户ID类型不匹配

  • Instagram Private API要求user_id参数为整数类型,若静态列表中存储的是字符串形式的数字,会导致API请求路径错误:
    # 错误示例:ID为字符串格式
    all_followers = [["14479686613", ""], ["2897711656", "PROFILE TEST. ATLANTA."]]
    # 正确做法:转换为整数
    all_followers = [[14479686613, ""], [2897711656, "PROFILE TEST. ATLANTA."]]
    

3. 会话权限或登录状态异常

  • 确认api实例已成功登录且会话未过期:
    • 在调用get_bios前添加验证,比如调用api.current_user()检查是否能返回当前用户信息;
    • 若会话过期,重新执行登录流程,确保user_name和password正确。

4. 目标用户隐私设置限制

  • 隐私账号未被登录账号关注时,API无法获取其信息,会返回404:
    • 用登录账号手动关注目标用户后再测试;
    • 在脚本中添加异常捕获,跳过无法访问的用户:
      def get_bios(followers):
          bios = []
          for follower in followers:
              follower_id = follower[0]
              try:
                  user_info = api.user_info(follower_id)
                  bios.append([follower_id, user_info['user']['biography']])
              except Exception as e:
                  print(f"无法获取用户ID {follower_id} 的信息: {str(e)}")
                  bios.append([follower_id, "无法获取"])
          return bios
      

验证步骤

  1. 单独测试单个有效ID:

    test_id = 2897711656  # 使用原脚本中正常工作的ID
    print(api.user_info(test_id)['user']['biography'])
    

    若此调用正常,说明静态列表中存在无效ID;若仍报错,检查登录状态或API版本。

  2. 检查API版本兼容性:
    若使用的instagram_private_api版本过旧,尝试更新:

    pip install --upgrade instagram-private-api
    

内容的提问来源于stack exchange,提问作者wizkids121

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 08:45:44