I'm trying to make an app where it displays the files and folders inside my google drive folder so I went to google apis and used the code I found on their page its here below
as I didn't expect it just let me log into my drive and then it returned me an error I'm providing a photo for it This is the error returned it says that
Message='client_secret' Source=D:\Study\Computer Science\G10\Paython 2nd semester\python consol app\python consol app\python_consol_app.py StackTrace: File "D:\Study\Computer Science\G10\Paython 2nd semester\python consol app\python consol app\python_consol_app.py", line 48, in main()
I managed to skip this error and renaming the json file and I solved this error only to find another error that says
Message=Authorized user info was not in the expected format, missing fields client_secret, client_id, refresh_token. Source=D:\Study\Computer Science\G10\Paython 2nd semester\python consol app\python consol app\python_consol_app.py StackTrace: File "D:\Study\Computer Science\G10\Paython 2nd semester\python consol app\python consol app\python_consol_app.py", line 48, in main()
so I'm wondering how should I solve such an issue also if my application can run into every single folder and subfolder
SCOPES = ['https://www.googleapis.com/auth/drive.metadata.readonly']
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.
"""
creds = None
if os.path.exists('token.json'):
creds = Credentials.from_authorized_user_file('token.json', SCOPES)
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
with open('token.json', 'w') as token:
token.write(creds.to_json())
service = build('drive', 'v3', credentials=creds)
results = service.files().list(
pageSize=10, fields="nextPageToken, files(id, name)").execute()
items = results.get('files', [])
if not items:
print('No files found.')
else:
print('Files:')
for item in items:
print(u'{0} ({1})'.format(item['name'], item['id']))
if __name__ == '__main__':
main()