2015-02-06 62 views
0

我能够使用在谷歌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 

我怎么会那么做蟒蛇这一要求?我目前正试图做到这一点:

api_key = '1122d' 
requests.get('https://www.googleapis.com/drive/v2/files/asdf?key=%s' % api_key) 

但是我得到了404.我该怎么做这个请求?

回答

1

You have to authenticate your request。我会建议使用谷歌的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() 
+0

感谢您的回答。现在我已经安装了,如何给我一个'api_key'和'file_id'下载文件? – David542 2015-02-06 00:22:36

+0

谢谢,请你举一个例子来说明'service = build_service(### Credentials here ###)'这个行吗? – David542 2015-02-06 00:38:59

相关问题