Быстрый старт в gDrive API

  • Published on
    12-Apr-2017

  • View
    207

  • Download
    0

Embed Size (px)

Transcript

<ul><li><p>(drive) API PyNSK</p><p>i32311113@icloud.com</p></li><li><p>Models</p><p>ClientGoogle</p><p>Your App</p><p>Server-Server</p><p>Client-Server</p></li><li><p>HowTo enable APIhttps://console.developers.google.com/project/ageless-valor-110414</p></li><li><p>HowTo enable APIhttps://console.developers.google.com/project/ageless-valor-110414/apiui/apiview/drive/overview</p><p>https://console.developers.go/</p></li><li><p>Authhttps://console.developers.google.com/project/ageless-valor-110414/apiui/credential</p></li><li><p>Authhttps://console.developers.google.com/project/ageless-valor-110414/apiui/credential/serviceaccount/390006575094-bm1e72sjish8m7d4500b0ht1vhn4mtdn@developer.gserviceaccount.com</p></li><li><p>Startpip install --upgrade pyOpenSSLpip install --upgrade google-api-python-client</p><p>from datetime import datefrom httplib2 import Httpfrom apiclient.discovery import buildfrom oauth2client.client import SignedJwtAssertionCredentialsfrom apiclient.http import MediaFileUploadimport random</p></li><li><p>Codedef auth():</p><p>client_email='390006575094-bm1e72sjish8m7d4500b0ht1vhn4mtdn\@developer.gserviceaccount.com'</p><p>with open('My Project-f5de14b11059.p12', 'r') as f:private_key=f.read()</p><p>credentials =SignedJwtAssertionCredentials(client_email,\private_key, 'https://www.googleapis.com/auth/drive')http =Http()credentials.authorize(http)service =build('drive', 'v2', http=http)return service</p></li><li><p>Examplesdef show(service):</p><p>Files =\service.files().list().execute()</p><p>forf infiles['items']:print f['title'], f['id']</p><p>def add(service, content):id =str(random.random())withopen('temp', 'w') asf:</p><p>f.write(content)body ={'title':str(date.today()) +id,\'description':id,\'mimeType':'text/plain'\}media_body=MediaFileUpload('temp', mimetype='text/plain',\</p><p>resumable=True)f =service.files().insert(body=body, media_body=media_body,\</p><p>convert=True).execute()permission ={ 'value':'','type':'anyone','role':'writer' }files =service.files().list().execute()forf infiles['items']:</p><p>try:p =service.permissions().insert(fileId=f['id'],\</p><p>body=permission).execute()except:</p><p>pass</p></li><li><p>ObjectJust example</p><p>mimeTypeapplication/vnd.google-apps.documentversion13appDataContentsFalsethumbnailLinkhttps://docs.google.com/feeds/vt?labels{u'restricted': False, u'starred': False,explicitlyTrashedFalseetag"pvTNHKA6KkAgXTpZXMwU4PlastModifyingUserName3900065750writersCanShareTrueowners[{u'emailAddress': u'3900065id1Wvm7MOpy8zFUIz69lP1y1Ck31UozmRN8yEAWHFRHULAlastModifyingUser{u'emailAddress': u'390006575094-bm1e72sjtitle2015-10-200.493659065111ownerNames[u'390006575094-bm1e72sjish8m7d4500b0lastViewedByMeDate2015-10-20T16:24:17.910Zparents[{u'isRoot': True, u'kind': u'drive#parentReference'exportLinks{u'text/html': u'https://docs.google.com/feedssharedTrue</p><p>description0.493659065111editableTruekinddrive#filemarkedViewedByMeDate1970-01-01T00:00:00.000ZmodifiedDate2015-10-20T16:24:17.910ZcreatedDate2015-10-20T16:24:16.858ZiconLinkhttps://ssl.gstatic.com/docs/doclist/images/icon_embedLinkhttps://docs.google.com/document/d/1Wvm7alternateLinkhttps://docs.google.com/document/d/1WvmcopyableTruemodifiedByMeDate2015-10-20T16:24:17.910ZuserPermission{u'kind': u'drive#permission', u'etag': u'"pspaces[u'drive']quotaBytesUsed0selfLinkhttps://www.googleapis.com/drive/v2/files/1Wvm</p></li><li><p>Links</p><p>https://console.developers.google.com</p><p>https://developers.google.com/drive/web/quickstart/python</p><p> 1 2 3 4 5 6 7 8 9 10 11</p></li></ul>

Recommended

View more >