gsutil使用boto 配置文件在 Google Cloud Storage 进行身份验证。
\n\n我在 console.developers.google.com 中生成 ClientID - 允许通过 python 脚本将文件放入 Google Drive:
\n\n#!/usr/bin/env python\n\nfrom apiclient.discovery import build\nfrom apiclient.http import MediaFileUpload\nimport httplib2\nfrom oauth2client.client import SignedJwtAssertionCredentials\n\ncredentials = SignedJwtAssertionCredentials(\nservice_account_name=\'301714561983-nkd8kalz1op3bdjn75ija1b7ef1sslpr@developer.gserviceaccount.com\',\nprivate_key=\'\'\'-----BEGIN PRIVATE KEY-----\n\xd0\xbf\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb0\xd1\x82\xd0\xbd\xd1\x8b\xd0\xb9 \xd0\xba\xd0\xbb\xd1\x8e\xd1\x87\xd0\xb8\xd0\xba \n-----END PRIVATE KEY-----\'\'\',\n scope = [\n \'https://www.googleapis.com/auth/drive\',\n \'https://www.googleapis.com/auth/drive.file\',\n \'https://www.googleapis.com/auth/drive.appdata\',\n \'https://www.googleapis.com/auth/drive.apps.readonly\'\n ]\n)\n\nhttp = httplib2.Http()\nhttp = credentials.authorize(http)\n\ndrive_folder_id = \'0C3ZU6kySEIuCT0ANM3RRVE1iME0\' #folder id\n\nservice = build(\'drive\', \'v2\', http=http)\n\nmedia_body = MediaFileUpload(\'document.txt\')\nbody = {\n \'title\': \'document.txt\',\n \'description\': \'backup\',\n \'mimeType\': \'text/plain\',\n \'parents\': [{\'id\': drive_folder_id}]\n}\n\nfile = service.files().insert(\n body=body,\n media_body=media_body).execute()\nRun Code Online (Sandbox Code Playgroud)\n\n我想使用 …