I created a website that I plan to connect to Google Drive. So, when students or teachers upload files, the files will go to their respective google drive accounts. Meanwhile, the only thing that goes into the database is the file link.
I've tried using Python Social Auth and implemented it successfully. But I'm still confused about how to use the access token I got to access the Google Drive API.
Please help me
Related
I am trying to access a Google Sheet stored in my Drive through the Google Sheets REST API.
This will just be a Python script without any user interaction. How can I authenticate my request using something like an access key or a service account?
I understand the concept of generating access keys or creating a service account in my Google Cloud console. But, I don't quite understand how the Sheet in my Drive can be associated with it.
I would like to know the steps I should follow in order to accomplish this. For instance, how can I send a request to this API endpoint?
GET https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetId}
Note: I want to do this using the REST API. I do not want to use a Python API that has already been developed. So, I simply want to hit the above endpoint using maybe the requests package.
Google does not permit API only access to Google (Workspace?) documents.
See Authorizing Requests
API keys authenticate programs.
OAuth is used to authenticate users and Google requires that users authenticate requests when access user data stored in Workspace documents.
Domain-wide Delegation enables the use of a Service Account to operate on behalf of users in situations such as this but it is only available for (paid) Workspace accounts.
I'm unsure how to refer to the free and paid (Workspace) versions.
For the Google Drive Python API, in all the tutorials I have seen, they require
users to create a project in their Google Dashboard, before obtaining a client ID and a client secret json file. I've been researching both the default Google Drive API and the pydrive module.
Is there a way for users to simply login to their Google Account with username and password,
without having to create a project? So once they login to their Google Account, they are free to
access all files in their Google Drive?
It's not possible to use the Drive API without creating a GCP project for the application. Otherwise Google has no idea what application is requesting access, and what scope of account access it should have.
Using simply a username and password to log in is not possible. You need to create a project and use OAuth.
it might be possible using some pysimplegui hackery or just simply modifying the code of a python based browser but in most cases it is not practical
except if you need to automate something (like renaming files ) that would take 1 hour in a place where you do not have access to GCP
I am looking at Google Drive API tutorials and they tell you to store credentials.json in my working directory (eg https://developers.google.com/drive/api/v3/quickstart/python).
My goal is to make a script which regularly runs on my system and downloads files from Google Drive. My concern is: does storing the credentials.json file leave me open to security risks? If anyone gets access to this file, can they not use it to gain access to all my Google Drive data?
If so, then how should I store the credentials file in a secure manner?
The credentials.json file is used to create user credentials for your application. If someone got a hold of that they could pretend to be your application and request access of users and then do what they wanted with user data. It is very important that you keep this file secure.
Note: If you are only accessing your google drive account and not one owned by other users then you should consider looking into service accounts.
I'm building a web app, where a user select a file from his drive using Google Picker API, but I want to get the full public link for the selected document, I already have an access token which I got on the frontend with JS and and the Google APIs, I want now to send it to the server (I already know that this is a bad practice, but this app is private and only some friends will use it) .
The docs of PyDrive says that you need the user to surf to some generated URL by pydrive get the access code and enter it, is there a way to authenticate with pydrive just through the access token I already have ?
Background
I've created a slack bot that listens in a channel for when a file is uploaded, downloads the content and re-uploads it to our Google Drive account and deletes it from Slack. This all works perfectly using slack-client api and google drive api in Python.
Problem
What I would like to recreate is the view that the Google Drive slack integration creates when you import a file from Google Drive, instead of just having a link (like my bot current is capable of).
I'm currently using slack_client.api_call("chat.postMessage", ..., unfurl_media=True, unfurl_links=True) however, that does not solve the problem (it still just appears as a link as seen above, instead of an attachment like the Google Drive integration.)
Anyone have any recomendations on how to achieve the same look at the Google Drive integration? The idea is that the thumbnails and previews of attachments should not go away, but everything should be hosted on Google Drive as opposed to Slack's servers since we share a ton of files.