我使用 React - javascript 在我的项目中通过谷歌驱动器创建了一个文件上传按钮。我使用 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 密钥?