python - Getting WebViewLinks with Google Drive -


i've started trying use google drive api. using quickstart guide set authentication, can print list of files , can make copies. works great, i'm having trouble trying access data file on drive. in particular, i'm trying webviewlink, when call .get receive small dictionary has barely of file's metadata. the documentation makes data should there default it's not appearing. couldn't find way flag requesting additional information.

credentials = get_credentials() http = credentials.authorize(httplib2.http()) service = discovery.build('drive', 'v3', http=http)  results = service.files().list(fields="nextpagetoken, files(id, name)").execute() items = results.get('files', []) if not items:     print('no files found.') else:     print('files:')     item in items:         print(item['name'], item['id'])         if "target file" in item['name']:             d = service.files().get(fileid=item['id']).execute()             print(repr(d)) 

this output of above code: (the formatting doing)

{u'mimetype': u'application/vnd.google-apps.document',   u'kind': u'drive#file',  u'id': u'1vo9cc8mgm67onvyx3_2f-syzljpr4_lteqzildwjgde',  u'name': u'fix tvp licence issues'} 

for confused code there missing that's basic get_credentials function api's quickstart page , constants , imports. completeness, here's stuff, unmodified in code:

from __future__ import print_function import httplib2 import os  apiclient import discovery import oauth2client oauth2client import client oauth2client import tools  scopes = 'https://www.googleapis.com/auth/drive' client_secret_file = 'client_secret.json' application_name = 'drive api python quickstart'  try:     import argparse     flags = argparse.argumentparser(parents=[tools.argparser]).parse_args() except importerror:     flags = none   def get_credentials():     """gets valid user credentials storage.      if nothing has been stored, or if stored credentials invalid,     oauth2 flow completed obtain new credentials.      returns:         credentials, obtained credential.     """     home_dir = os.path.expanduser('~')     credential_dir = os.path.join(home_dir, '.credentials')     if not os.path.exists(credential_dir):         os.makedirs(credential_dir)     credential_path = os.path.join(credential_dir,                                    'drive-python-quickstart.json')      store = oauth2client.file.storage(credential_path)     credentials = store.get()     if not credentials or credentials.invalid:         flow = client.flow_from_clientsecrets(client_secret_file, scopes)         flow.user_agent = application_name         if flags:             credentials = tools.run_flow(flow, store, flags)         else: # needed compatibility python 2.6             credentials = tools.run(flow, store)         print('storing credentials ' + credential_path)     return credentials 

so what's missing, how can api return meta data that's not appearing right now?

you close. newer version of drive api v3, retrieve other metadata properties, have add fields parameter specify additional properties include in partial response.

in case, since looking retrieve webviewlinkproperty request should similar this:

results = service.files().list(         pagesize=10,fields="nextpagetoken, files(id, name, webviewlink)").execute()  

to display items response:

for item in items:             print('{0} {1} {2}'.format(item['name'], item['id'], item['webviewlink'])) 

i suggest try out api explorer can view additional metadata properties display on response.

good luck , hope helps ! :)


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -