![](/img/trans.png)
[英]How to upload a file on Google Drive using python with POST request?
[英]How to request a File in Google Drive
我可以使用Google API資源管理器中的以下請求進行請求:
GET https://www.googleapis.com/drive/v2/files/asdf?key={YOUR_API_KEY}
Authorization: Bearer ya29.EQEo6DJmR0Z-FngYc9nAL5iiidB8TBI7ysBDD6TARiqMtFjmMagLew0oC-vxj9HjojXjja46-5LSEQ
X-JavaScript-User-Agent: Google APIs Explorer
我將如何在python中執行此請求? 我目前正在嘗試使用:
api_key = '1122d'
requests.get('https://www.googleapis.com/drive/v2/files/asdf?key=%s' % api_key)
但是我收到404。我將如何處理此請求?
您必須驗證您的請求 。 我建議使用Google的python客戶端刪除很多樣板:
pip install --upgrade google-api-python-client
從文檔:
from apiclient.discovery import build
def build_service(credentials):
http = httplib2.Http()
http = credentials.authorize(http)
return build('drive', 'v2', http=http)
然后使用該服務:
from apiclient import errors
try:
service = build_service(### Credentials here ###)
file = service.files().get(fileId=file_id).execute()
print 'Title: %s' % file['title']
print 'Description: %s' % file['description']
print 'MIME type: %s' % file['mimeType']
except errors.HttpError, error:
if error.resp.status == 401:
# Credentials have been revoked.
# TODO: Redirect the user to the authorization URL.
raise NotImplementedError()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.