获得超过未经身份使用的每日限制。继续使用需要注册。添加'https://www.googleapis.com/auth/drive'时。如果我将其从范围中删除,则适用于与其他范围有关的所有其他功能。我需要在范围中复制文件。
public handleClientLoad() {
gapi.load('client:auth2', function () {
gapi.client.init({
discoveryDocs: ['https://sheets.googleapis.com/$discovery/rest?version=v4',
'https://www.googleapis.com/discovery/v1/apis/drive/v3/rest'],
clientId: 'MyclientID*.apps.googleusercontent.com',
scope: ` https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/drive.metadata.readonly https://www.googleapis.com/auth/spreadsheets `
}).then(() => {
gapi.client.drive.files.copy({
'fileId': 'My File ID',
'resource': {
'parents': [
'MY Parent File'
],
'name': 'My File Name'
}
})
});
});
}
当您提交无授权HTTP标头的API请求时返回错误。您可以追踪网络流量以查看是否是这种情况。如果是这样,我怀疑您正在执行诸如错误的语法之类的事情来打破GAPI客户端库,以使其无法正常运行。有任何控制台消息吗?
我能够通过在原始问题中添加此代码来解决问题。
var GoogleAuth;
gapi.load('client:auth2', function () {
// callback
.then(() => {
**GoogleAuth = gapi.auth2.getAuthInstance();
GoogleAuth.signIn();**
gapi.client.drive.files.copy({
// implement functionality