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

无法通过编程库从EpicGames API获取authorizationCode求助

问题分析与解决方案

核心原因

该接口需要验证已登录Epic账号的会话状态,浏览器访问时会自动携带登录后生成的Cookie,而axios等HTTP库默认不会加载浏览器的Cookie,导致接口无法识别你的登录状态,因此返回null。

解决方案

1. 提取浏览器中的登录Cookie

打开浏览器开发者工具(快捷键F12):

  • 切换到「Application」(Chrome)或「存储」(Firefox)标签页
  • 展开「Cookies」→ 选择https://www.epicgames.com
  • 复制所有前缀为EPIC_的Cookie(比如EPIC_SESSION、EPIC_AUTH等),拼接成key1=value1; key2=value2; ...的格式

2. 修改axios请求携带Cookie

在请求头中加入提取到的Cookie,并开启凭证携带选项:

const axios = require("axios");
const codeEndpoint =
  "https://www.epicgames.com/id/api/redirect?clientId=3446cd72694c4a4485d81b77adbb2141&responseType=code";

async function codeFetch(url) {
  const res = await axios.get(url, {
    headers: {
      // 替换为你从浏览器复制的完整Cookie字符串
      "Cookie": "EPIC_SESSION=xxxxxx; EPIC_AUTH=xxxxxx; ..."
    },
    // 确保跨域请求携带凭证
    withCredentials: true
  });
  return res.data;
}

codeFetch(codeEndpoint).then((r) => console.log(r.authorizationCode));

注意事项

  • Cookie存在有效期,过期后需要重新从浏览器提取
  • 切勿将Cookie内容上传至公共代码仓库,避免账号被盗风险
  • 确保请求域名与Cookie的域名完全一致,否则浏览器会拒绝携带Cookie

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 10:36:22