after days of searching, I have concluded that the right question would be better. I am working on app backend. I need it to backup some files regularly on Google Drive. Do I understand it correctly that I need Google For Work account so I can use Server2Server?
According to this
https://developers.google.com/api-client-library/php/auth/service-accounts
Google wants me to grant access only via Google For Work account. Have I missed anything if I just want my web based php script executed by cron to backup few files on Google Drive? Is there any other option?
Thank you!
The account that Google Drive connects to is determined by the content of your OAuth Access Token. If you'd like to do server-to-drive, where the Drive account is your own, see the instructions in How do I authorise an app (web or installed) without user intervention? (canonical ?)
Related
I would first like to apologize if this question is a duplicate; perhaps I'm not being able to word what I need correctly because I really couldn't find a solution for my need after several hours of research...
I need logged users of my application (PHP, Laravel 5.7) to be able to download files from a specific folder on my Google Drive on my behalf; of course, without having my credentials, but I'm being unable to figure out how to make the request; all the examples I found were to allow users to download their own files after they authenticate with their credentials. Since Google Drive API uses OAUTH2, I thought I could just send a request to some endpoint with Authentication header bearing my token and the "file id" and the download would start but after scavenging the docs I still couldn't find this endpoint.
EDIT: Thanks to Osama Ibrahim for pointing to me the above endpoint.
Sorry for long text, tl;dr:
I need to know how my application can download a file on my drive programatically, requesting a token with my credentials without having to go through the google login UI.
I have a small site/web application where registered users can see some files that I periodically prepare for them; I store these files in separate directories and every user can only see and download their own files.
Now, I'm moving these directories to Google Drive and I would keep functionalities like file listing and downloading.
Reading the official docs I found some interesting examples about file download/upload, but all of them talk about authorization that user must give in order to access to their Drive and this is not what I'm looking for, I don't want access to their Drive!
As I can see, the doc is not contempling the case that someone may want to give (read-only) access to own Drive. But maybe I'm missing something...
Basically, I need the list of files on my Drive account and, if requested, a way to download one (or more). The only one that has the auth to Drive account is my server, users will send request from it.
Is it possible? I think yes, but I can't find any docs about that. How can I authorize my server?
I think you're looking for the Using OAuth 2.0 for Web Server Applications where you'll be using service accounts to achieve your goal.
"This document explains how web server applications use the Google API
Client Library for PHP to implement OAuth 2.0 authorization to access
Google APIs. OAuth 2.0 allows users to share specific data with an
application while keeping their usernames, passwords, and other
information private. For example, an application can use OAuth 2.0 to
obtain permission from users to store files in their Google Drives."
The snippets are in PHP too, so it works in your favor.
I want to create a new Id Client Oauth 2.0 for Google Drive API, then generate the object JSON (oauth credentials), download it and place it in a specific folder, without the use of the console developers google. Is there a script (in php or javascript) that produce this with the email and password of a google account?
I want to create this "standalone script" because I dont want that the client must go before on the google console (although it will be for one-time).
thanks,
Matteo
It is not possible to programmatically create a project on Google developer console. The only way to create a new project is to do it though the website manually.
You are not going to find a script or anything to allow you to do this. The only think that remotely resembles this is the Google Cloud Resource Manager API but its not going to let you create credentials.
I am using PHP Google Client code and I am using service account too. I completed the following codes using service account:
Creating a folder that anyone can access.
Insert a file in that folder that anyone can also access.
It worked with following Google drive share link and also shared to other email, also https://drive.google.com/folderview?id=0B7DT8HrNe_iDQkhnQ3REMkxwM2M.
But my question is, I am sharing a file to a single user with PHP Google Client and automatically that user gets the file in their Google Drive. Any ideas?
I am trying to upload files into Google Drive using the Google Drive API but the problem is that I have to be logged-in every time. I searched a lot but no luck.
Is there any way I can do authentication process without manual and logged-in intervention?
If you are doing it correctly, you should only have to authenticate once save the refresh token, and use the refresh token in all your other calls.
Second option would be a service account but that is tricky as files are uploaded to the service account, unless you give it permission to upload to your own Google drive account.