【发布时间】:2021-12-20 16:39:41
【问题描述】:
上下文
我想通过浏览器从 Google Drive 下载文件。 我可以通过drive.get 访问文件的数据和详细信息,但我无法导出文件。我在响应中没有看到 binaryString。
然后我联系了 API-Explore,但我也无法下载任何内容。 有什么想法/提示吗?
注意我的...
-
SCOPES: 'https://www.googleapis.com/auth/drive' - 我在Credentials Page获得了一个开发者
API Key - 我获得了
OAuth 2.0 Client IDs
为你重现
公共你好世界文档helloWorld
详情
mimeType:'application/vnd.google-apps.document'
id:'1O2ORp9te3FzqTFZkPLGNGvAnzcKBhdGZ-lu8TgABPrY'
API 资源管理器字符串
响应
{
"error": {
"errors": [
{
"domain": "global",
"reason": "badRequest",
"message": "The requested conversion is not supported.",
"locationType": "parameter",
"location": "convertTo"
}
],
"code": 400,
"message": "The requested conversion is not supported."
}
}
本地代码
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<script type="text/javascript">
var developerKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
var clientId = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
var appId = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
var scope = 'https://www.googleapis.com/auth/drive.drive'
const mimeType = 'application/vnd.google-apps.document'
const fileID = '1O2ORp9te3FzqTFZkPLGNGvAnzcKBhdGZ-lu8TgABPrY'
function load() {
gapi.load('client:auth2', () => {
console.log(gapi)
gapi.client
.init({
clientId,
scope,
apiKey: developerKey,
discoveryDocs: ['https://www.googleapis.com/discovery/v1/apis/drive/v3/rest'],
})
.then(
() => {
gapi.auth2.getAuthInstance().signIn()
gapi.client.load('drive', 'v3', () => {
gapi.client.drive.files
.export({
fileID,
mimeType,
})
.then(res => console.log(res))
.catch(error => console.error(error))
})
},
error => console.error(error)
)
})
}
</script>
</head>
<body>
<div id="result"></div>
<script type="text/javascript" src="https://apis.google.com/js/api.js?onload=load"></script>
</body>
</html>
参考和有用的链接
【问题讨论】:
标签: google-api google-drive-api google-apis-explorer