2

I have this python code snippet to upload file to google drive.

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
import os

g_login = GoogleAuth()
g_login.LocalWebserverAuth()
drive = GoogleDrive(g_login)

with open("test_gdrive.csv",'r',encoding = 'unicode_escape') as file:
    file_drive = drive.CreateFile({"mimeType": "text/csv" })  
    file_drive.SetContentString(file.read()) 
    file_drive.Upload({'convert': True})  

It is working completely fine. Now i want to automate this with a cronjob written on a linux server.When i run this on the server, it is asking for local browser authentication and could not proceed further. How can i write a cronjob in server to upload the file to gdrive everyday? Is it possible ? I have read at places that it violates google policies and cant be done. If that is the case,is there any other way ?

Karanam Krishna
  • 365
  • 2
  • 16
  • I am curious about the violation of google policies. As far as I know you can automate the upload of a file without any problem, where have you read that? Also what is your problem right know, why can you just execute the code as it is? – Raserhin Sep 15 '20 at 08:10
  • 3
    When i try it from a machine it fires up the local browser for authentication something like this : https://accounts.google.com/o/oauth2/auth?client_id=XXXXXXXX how can it authenticate from machine ? If i copy that and open it in local, it is trying to redirect back to the source from where the request came and it fails to direct it to my machine. – Karanam Krishna Apr 27 '21 at 07:15

0 Answers0