我正在使用 google Oauth2 客户端脚本,但在“requestAccessToken”函数中出现了 2 个错误。见下图
在这里,我动态加载“https://accounts.google.com/gsi/client”脚本,加载后我使用 initTokenClient 函数创建 tokenClient。
当用户单击按钮时,我检查令牌是否已可用,如果没有,则我将发送对 google auth popup tokenClient.current.requestAccessToken({ Prompt: 'consent' }); 的请求 但是这个requestAccessToken函数给我一个名为c.trim() 的错误,它不是一个 funciton。据我发现它来自该函数的内部实现
我还在同一个地方收到另一个 CORS 错误。
重现链接:https://codesandbox.io/s/nostalgic-ives-wngw3v ?file=/src/Picker.jsx
import React, { useEffect, useRef, useState } from 'react';
import loadScript from 'load-script';
const GOOGLE_INDENTITY_URL = 'https://accounts.google.com/gsi/client';
const clientId = '865996907937-t2ca9nu95hv87f204t11gikb2rqm3s4v.apps.googleusercontent.com';
const scope = ['https://www.googleapis.com/auth/drive.readonly'];
let scriptLoadingStarted = false;
export default function TryPicker() {
const tokenClient = useRef();
const isGoogleAuthReady = () => {
return !!window.google?.accounts?.oauth2;
}; …Run Code Online (Sandbox Code Playgroud) 我在 http 请求架构中找不到任何原始标头。那么它是从哪里来的。我在互联网上搜索它,但没有找到任何有用的内容。