asked    Godfery     2018-10-22       python       77 view        1 Answer

[SOLVED] Downloading Google Documents using api

this is shareable link link to file

id = 1wzCjl51u131v1KBgpbiKLJs8DPPakhXCFosfYjp7BY0

so manage downloads documentation.

file_id = '11wzCjl51u131v1KBgpbiKLJs8DPPakhXCFosfYjp7BY0'
request = drive_service.files().export_media(fileId=file_id,
fh = io.BytesIO()
downloader = MediaIoBaseDownload(fh, request)
done = False
while done is False:
    status, done = downloader.next_chunk()
    print ("Download %d%%." % int(status.progress() * 100))

i saved the file as, run using f5 and got this error

line 2, in request = drive_service.files().export_media(fileId=file_id, NameError: name 'drive_service' is not defined

  1 Answer  

        answered    Evan     2018-10-22      

First off you cant be sure that the id you find in the shareable link is in fact the id of the file on google drive this is not always the case. Actually I have never known this to be the case

drive_service' is not defined

Second you need create the drive service and be authenticated before you can run that code. You should try following the python quickstart

from __future__ import print_function
from googleapiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools

# If modifying these scopes, delete the file token.json.

def main():
    """Shows basic usage of the Drive v3 API.
    Prints the names and ids of the first 10 files the user has access to.
    store = file.Storage('token.json')
    creds = store.get()
    if not creds or creds.invalid:
        flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
        creds = tools.run_flow(flow, store)
    service = build('drive', 'v3', http=creds.authorize(Http()))

    # Call the Drive v3 API
    results = service.files().list(
        pageSize=10, fields="nextPageToken, files(id, name)").execute()
    items = results.get('files', [])

    if not items:
        print('No files found.')
        for item in items:
            print('{0} ({1})'.format(item['name'], item['id']))

if __name__ == '__main__':

Your Answer

 2018-10-22         Regan

How to stop server in Client Server multithreading

I am implementing a multi-threaded client-server application in java. I want to implement JDBC in this program and I want my server to retrieve data from the database whenever it is started. I will store that data in my collection instances, perform manipulations on data and when server completes execution, I need to store the data back to the database. The problem is that the server is in an infinite loop waiting for clients and I am not able to figure out how to make the server stop.This is my server program:import*;import java.text.*;import java.util.*;import ja...
 java                     2 answers                     57 view
 2018-10-22         Zara

TF205020 and TF30063 cannot connect to server errors when opening Visual Studio 2017

I'm getting this error in the output window every time I open Visual Studio 2017 (v. 15.3.2):And then when I click on Team Explorer I get this popup error: After closing that pop-up, I can still connect normally to the TFS server and my projects through "Manage Connections" and then continue my work normally, but the next time I open up Visual Studio I'll get these errors again.Things I've noticed:In the TF205020 error message, "Could not connect to server '{url}'",the URL is incorrect. It has an additional directory after thedomain e.g.\mycompany...
 tfs                     1 answers                     57 view
 2018-10-22         Kay

Get json field value by variable with jq

I am trying to read the value of a field of a json variable, the field name is stored in a variable as well.What I tried:$ jsonVar=`cat test-config.json`$ echo $jsonVar{ "server-test": "xxx", "server2-test": "xxx", "server3-test": "xxx"}$ echo $itserver-test$ itVersion=$(jq --arg test "${it}" '.["${test}"]' <<< $jsonVar);$ echo $itVersionnull$itVersion should now have the value of "server-test" but is null, it seems my JQ command is wrong, but I cant figure out why. The variable is only accessible as $var, not ${var}. Additionnaly, it is expanded to a quoted str...
 bash                     1 answers                     62 view