我使用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密钥?
1条答案
按热度按时间sycxhyv71#
您是否已尝试激活您的API密钥?
https://developers.google.com/drive/picker/guides/overview