1

I've been working on a Twitter app with a friend that pulls its content from a Google Drive folder, then moves the files to a different folder when it's done. I had everything working perfectly until I decided to try to update which Google account and Drive folders we were using. I made certain to double check I updated all the authentication codes and folder IDs, but now the code to move the file in GDrive at the end no longer works and I'm not sure what the issue is. The whole code looks like this:

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

gauth = GoogleAuth()
gauth.LoadCredentialsFile("mycreds.txt")
if gauth.credentials is None:
    gauth.LocalWebserverAuth()
elif gauth.access_token_expired:
    gauth.Refresh()
else:
    gauth.Authorize()

gauth.SaveCredentialsFile("mycreds.txt")

drive = GoogleDrive(gauth)

file_list = drive.ListFile({'q': "'# folder1 id' in parents and trashed=false", 'maxResults': 1}).GetList()
print('Received %s files from Files.list()' % len(file_list)) # <= 1
for file1 in file_list:
    print('title: %s, id: %s' % (file1['title'], file1['id']))

for i, file1 in enumerate(sorted(file_list, key = lambda x: x['title']), start=1):
    print('Downloading {} from GDrive ({}/{})'.format(file1['title'], file1['id'], i, len(file_list)))
    file1.GetContentFile(file1['title'])

consumer_key = '# consumerkey'
consumer_secret = '# consumersecret'
access_token = '# accesstoken'
access_token_secret = '# accesstokensecret'

auth = tweepy.OAuthHandler (consumer_key, consumer_secret)
auth.set_access_token (access_token, access_token_secret)
api = tweepy.API (auth, wait_on_rate_limit = True)

def upload_media(text, filename):
    media = api.media_upload(filename)
    api.update_status(text, media_ids = [media.media_id_string])

upload_media('', file1['title'])

if file1['title'] == '# folder 2 id':
    folderId = file1['id']

file2 = drive.CreateFile({'id': file1['id']})
file2['parents'] = [{"kind": "drive#parentReference", "id": '# folder2 id'}]
file2.Upload()

os.remove(file1['title'])

Like I said, it was all working perfectly until I changed accounts and folder codes, but now when I try to run it, the file doesn't move in GDrive as on the previous set up. Does anyone know what might be going on here? Maybe I forgot a step when setting up the new Google app? I'm very new and a lot of this is pasted together from YouTube videos and forum posts, I'm starting to understand how it all works and fits together but I'm stumped on this. The script just finishes running and acts like it did everything right with no errors reported.

UPDATE: I made a new script in a new directory using the original account and folder locations that had worked and now they don't work either. Seriously, how could it work this morning but not now?

double-beep
  • 5,031
  • 17
  • 33
  • 41
mortypie
  • 11
  • 2

0 Answers0