React 和 Google Drive Picker

问题描述 投票:0回答:1

我在我的项目中使用 React - javascript 通过 google drive 创建了一个文件上传按钮。我使用 npm i react-google-drive-picker 做到了这一点。我使用了您接下来看到的代码:

import  { useEffect } from 'react';
import useDrivePicker from 'react-google-drive-picker'


function App() {
  const [openPicker, data] = useDrivePicker();
  // const customViewsArray = [new google.picker.DocsView()]; // custom view
  const handleOpenPicker = () => {
    openPicker({
    
      clientId: "*******************",
      developerKey: "*****************",
      viewId: "DOCS",
      
      
      // token: token, // pass oauth token in case you already have one
      showUploadView: true,
      showUploadFolders: true,
      supportDrives: true,
      multiselect: true,
      
      // customViews: customViewsArray, // custom view
    })
  }

  useEffect(() => {
    // do anything with the selected/uploaded files
    if(data){
      data.docs.map(i => console.log(i.name))
    }
  }, [data])


  return (
    <div>
        <button className="picker"onClick={() => handleOpenPicker()}>
        
        <p>Import from Google Drive</p>
        


        </button>
    </div>
  );
}

export default App;

有效,当我点击从谷歌驱动器导入按钮时,显示帐户选择菜单然后我选择一个帐户,但它说 API 开发人员密钥无效。

那么,我如何在此代码中导入我的 API 密钥?

javascript reactjs google-drive-api google-drive-picker
1个回答
0
投票

您是否已尝试激活您的 API KEY ??

https://developers.google.com/drive/picker/guides/overview

© www.soinside.com 2019 - 2024. All rights reserved.