【问题标题】:How to solve responseJSON: {error: "invalid_request", error_description: "Missing required parameter: code"}如何解决 responseJSON: {error: "invalid_request", error_description: "Missing required parameter: code"}
【发布时间】:2020-11-17 09:14:21
【问题描述】:

我正在尝试使用 Vuejs 和 Javascript 从我的 Web 应用程序将文件上传到 Google Drive,但是当我发送请求时,它会标记该错误。 我检查了变量code的值是null,甚至变量window.location.search也是一个空字符串,但我没有知道代码变量在请求中应该有什么值。

这是代码部分:

  const urlParams = new URLSearchParams(window.location.search);
  console.log ("Value of window.location.search", window.location.search);
  const code = urlParams.get('code');
  console.log ("Valor de code", code);
  const redirect_uri = "http://localhost:3000/formacionProf"
  const client_secret = clientSecret;
  const scope = "https://www.googleapis.com/auth/drive";
  let access_token= "";
  let client_id = clientID;

  $.ajax({
    type: 'POST',
    url: "https://www.googleapis.com/oauth2/v4/token",
    data: {
      code: code,
      redirect_uri: redirect_uri,
      client_secret: client_secret,
      client_id: client_id,
      scope: scope,
      grant_type: "authorization_code"
    },
    dataType: "json",
    success: function(resultData) {
      localStorage.setItem("accessToken",resultData.access_token);
      localStorage.setItem("refreshToken",resultData.refreshToken);
      localStorage.setItem("expires_in",resultData.expires_in);
      window.history.pushState({}, document.title, "/formacionProf");
    },
    error: function (error) {
        console.log(error);
    }
  });

感谢您的宝贵时间。

【问题讨论】:

标签: javascript ajax google-api


【解决方案1】:

您正在处理的页面是来自google api的回调url,因此当它们重定向到您的页面时,它们将传递“代码”等参数。

window.location.search 

表示当前 url 中的查询字符串。因此,也许您需要通过从他们的页面重定向来进行测试。

【讨论】:

    猜你喜欢
    • 2022-10-14
    • 2022-12-22
    • 2022-10-09
    • 2023-01-30
    • 2021-05-02
    • 1970-01-01
    • 1970-01-01
    • 2020-04-20
    • 1970-01-01
    相关资源
    最近更新 更多