我在 python 中创建了一个网络应用程序来在我的 Google Drive 帐户之间复制文件。公开共享文件到我的帐户。
我收到以下错误
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
"extendedHelp": "https://code.google.com/apis/console"
}
],
"code": 403,
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
}
}
我尝试了一切,更改范围,在 Google Console 中启用 SDK 等。问题是这个错误似乎只在我复制一些文件时出现,并且该应用程序适用于其他文件,甚至是同一帐户中的文件。
我正在使用 pydrive 来处理身份验证,遵循我的操作方式:
def LogIn(self):
extDataDir = os.getcwd()
ext_config = os.path.join(extDataDir, 'client_secrets.json')
dir_path = extDataDir
temp_folder = extDataDir
gauth = GoogleAuth(os.path.join(extDataDir,'settings.yaml'))
gauth.DEFAULT_SETTINGS['client_config_file'] = ext_config
gauth.settings['save_credentials_file'] = os.path.join(temp_folder, "cred_copyfiles.txt")
gauth.LoadCredentialsFile(os.path.join(temp_folder, "cred_copyfiles.txt"))
if gauth.credentials is None:
# Authenticate if they're not there
gauth.LocalWebserverAuth()
elif gauth.access_token_expired:
# Refresh them if expired
try:
gauth.Refresh()
except:
gauth.LocalWebserverAuth()
else:
gauth.Authorize()
return GoogleDrive(gauth)
这是我的 settings.yaml
client_config_backend: settings
client_config:
client_id: my_clent_di
client_secret: my_client_secret
save_credentials: True
save_credentials_backend: file
save_credentials_file: cred_copyfiles.txt
get_refresh_token: True
oauth_scope:
- https://www.googleapis.com/auth/drive
我使用 Google 的驱动器API 文档中的示例复制文件
drive.auth.service.files().copy(fileId=f['id'],body={"parents": [{"kind": "drive#fileLink","id": save_folder_id}]}).execute()
同样,这似乎不是身份验证的问题,因为它适用于某些文件而不适用于其他文件。甚至同一帐户中的文件。有谁知道这个问题的解决方案?
编辑:根据建议,我通过传递 pydrive 使用 DriveAPI 构建身份验证,我得到了同样的错误。
我发现了如何获取请求:
drive.auth.service.files().copy(fileId=f['id'],body={"parents": [{"kind": "drive#fileLink","id": save_folder_id}]}).to_json()
这里的请求
{"resumable_uri": null, "resumable": null, "uri": "https://www.googleapis.com/drive/v2/files/file_id/copy?alt=json", "body_size": 79, "response_callbacks": [], "body": "{\"parents\": [{\"id\": \"file_id\", \"kind\": \"drive#fileLink\"}]}", "resumable_progress": 0, "_in_error_state": false, "method": "POST", "methodId": "drive.files.copy", "headers": {"user-agent": "google-api-python-client/1.6.1 (gzip)", "content-type": "application/json", "accept-encoding": "gzip, deflate", "accept": "application/json"}}