Porting files from RESTFul to Google Drive Android API(GDAA). - google-drive-android-api

I'd like to solicit an expert advice on the following problem:
I have thousands of files (jpeg images) created under different authorizations in Google Drive. I can see all of them using the RESTful API (DRIVE scope) and can easily collect the file IDs of the subset I need. This collection has to be ported (make visible) to the new app version under the GDAA. And I know that GDAA's 'resource ID' is the RESTful's 'file ID'. I can sure bring all of the files to the Android device (using RESTful API) and re-insert them into the GDAA, but it is wasteful.
So, the question finally emerges:
Having collection of 'resource IDs', is there an easy way to port these files into the GDAA that has FILES scope and its own new authorization identity? Using the Android app only?

If I understand what you are asking, you want to transfer an authorization from one app to another? That is not possible. A user authorized you to access the file with a particular app. They need to reauthorize you to access the file with any new app.

Related

What a client has to enable to use my app to edit their Google Sheet

Let's say I wrote a simple desktop app that reads some data from a Google Sheet, goes off and finds the answer and comes back and writes it into the Google Sheet. Now hundreds of people have sheets and want to use my program to process them. I post my program and let them download it for free.
Here is the sequence I think the end user needs to follow to get it to work:
1. Go to the GCP console and create a new project
2. Enable the Google Drive and Google Sheets APIs
3. Create a credentials JSON file with access as the Project Editor.
4. Create the Sheet if needed.
5. Copy the email out of the JSON file and Share it in the Sheet.
6. Make sure the JSON file is named right and in the right directory so the app finds it.
That all seems like a lot just so an app can read and write to a Google Sheet. Is there a simpler interface I am missing?
Answer:
There are steps that will always need to be completed when a user runs an application that accesses the Google APIs as themself, however depending on the case some of these may be simplified or circumvented.
More information:
There are a few things that you will need to bear in mind when creating an application for others to use, I'll summarise these points here and explain in a bit further detail:
To use a G Suite API, a Google Cloud Platform (GCP) Project needs to be owned and have the API associated.
In order to use the Google APIs (such as Drive and Sheets) its use must be enabled within the project that will use it.
If a user is running an application as themself, they will need to authenticate the application with their own credentials.
As per Google's documentation for Setting up a project:
Every application that uses Google APIs needs an associated Google Cloud Platform project. This project is a set of configuration settings that define how your application interacts with Google services and what resources it can use.
Resultantly, if your users will be running the application themselves, from a version of the app which is unpublished and not in the G Suite Marketplace then yes - they will need to create a GCP project, enable the respective APIs and use their personal credential file to run your application.
In reality this isn't the way G Suite Applications should be created, distributed and maintained and I can't reccommend that you do it this way. The G Suite marketplace is there to put in place a way of application distribution while removing the need for each user to create a GCP project and authenticate.
Things you can do:
With this in mind, there are a couple of things you can do to which will make the process of what you're doing slightly easier/shorter. Please bear in mind this isn't recommended for application distribution and more for testing purposes:
You can combine points 1, 2 and 3 in your question by having users click the Enable the Google Sheets API button on the Python Quickstart page. This button creates a new GCP project, enables the API and gives a credential file download link in one fell swoop.
Rather than having the user create the sheet themselves, you can code a sheet existence check in your program and create it if it doesn't already exist:
from pprint import pprint
from googleapiclient import discovery
# assuming you already have all your authentication code
sheetsService = discovery.build("sheets", "v4", credentials = credentials)
# add request body to variable sheetBody:
sheetBody = {}
# create the sheet:
sheetsService.spreadsheets().create(body = sheetBody).execute()
The https://www.googleapis.com/auth/drive.file scope allows your application to only access files created by itself which gives your application an extra level of security and trust.
In the sheetBody contents you can imclude the email address of the account running the application, if applicable, by running a Files: list request of the Drive API and reading the owners.emailAddress property of the response, to save reading the address from the JSON file.
References:
G Suite Developer:
G Suite APIs
Set Up Your Project
Build your app
Google Sheets API v4:
Python Quickstart
Google Drive API v3:
Files resource

Store data into google drive's backup tab instead of drive folders

I need to implement same thing like whatsapp storing all chat history to google drive on clicking on backup button in app. And same restore it in new device as required.
I have look for below references for implementing this, but some how I was not able to do it successfully.
https://developer.android.com/guide/topics/data/backup.html
https://developer.android.com/guide/topics/data/data-storage.html
https://developer.android.com/guide/topics/data/data-storage.html#db
Will this data backup option will help in my requirements or I need to do something else?
I successfully developed the file upload to google drive folders, but i need that data in the backup tab of google drive with app name.
can any one guide me how I can implement this or provide me some references?
Thanks in advance..!
You may refer with this documentation. The Google Drive API includes a special hidden folder that your app can use to store application data.
Note: This feature now uses the alias appDataFolder in place of appdata and appfolder.
To be able to use your Application Data folder, request access to the following scope:
https://www.googleapis.com/auth/drive.appdata
For more information about scopes and how to request access to them, see Authorizing Your App with Google Drive.

Accessing a public google drive without authentication using Corona sdk

I have two public folders in my google drive and I want my app to be able read images from one folder and read and write images to another folder. Is there a way to do this using the google api or any GET method and hopefully without needing to authorize or authenticate the user's google account? Thank you!
It's a cross platform application being developed in Lua using the Corona sdk
Unfortunately, you cannot access a particular drive without any authentication/authorization.
Every request your application sends to the Drive API must include an
authorization token. The token also identifies your application to
Google.
Same question was also raised in this SO post.
But there is an alternative if you go further in the answer of the SO post. This link maybe useful if you want to try the alternative.

Allowing read and write access to Google Drive files to unauthenticated clients

We have been working on a web service (http://www.genomespace.org/) that allows computational biology tools that implement our REST API to, among other things, read and write files stored on "The Cloud".
Our default file storage is a common Amazon S3 bucket, but we now allow users to mount their own private S3 bucket as well as files on Dropbox.
We are now trying to enable similar functionality for Google Drive and have run into some problems unique to Google Drive that we have not encountered with S3 or Dropbox.
Only way to allow clients that are not Google-authenticated to read files unobtrusively is to make the files "Public". Our preference would be that once the user has authorized access to our application via OAuth2, the user files could remain "Private" in Google Drive.
However, even though the user has already authorized our web service to offline access to their "Private" files, we have not found a way to generate a URL that a client authorized by our system can use to GET the file directly without the client being logged into Google as well.
The closest we have come to this functionality has been to change the file permissions to "Anyone with Link", except that for files greater than 20MB Google insists on returning an intermediate web page warning that the file has not been scanned for viruses. In addition to having to mess with file permissions, this would break our existing clients. Only when the file is "Public" and we utilize URLs of the form https://googledrive.com/host/PARENT_FOLDER_ID/FILENAME can non-Google clients read the files without interference.
Have not found any way for clients that are not Google-authenticated to upload a file to Google Drive. Our API allows our authorized clients to PUT files directly to the backing file storage using URLs provided by our server. However, even if a folder is marked "Public", the client requires Google authentication credentials to save to Google Drive. We could deal with both of these issues with intermediate hops through our system (e.g., our web server would first download the file from Google Drive and then allow the client to GET it) however this would be woefully inefficient and, hopefully, unnecessary. These problems have been discussed multiple times before on stackoverflow (e.g. here and here and have read the responses very carefully, but have not seen any recent discussion.
The Google folks direct their API users to post on stackoverflow for support, so I am hoping for a fresh look from insiders.
The general answer is: dont make the drive requests through the user's browser. Insead do everything from your servers. You are the one having the (refresh) tokens for users, so you should make all requests like a proxy between the user and Drive. Same for downloading, you download it and return to the user. As long as you use each drive's token there shouldnt be rate limit/quota issues.

Retrieve all image files using Dropbox Core API

I am working on Dropbox Core API with Google App Engine (python). There seems to be some problems with Dropbox-python-sdk on GAE. Therefore, I have choose to use the Core APIs directly.
My app is trying to retrieve all image files from a user's dropbox (with file type permission). But I couldn't find a way to get all files without specifying the root/path (all the APIs stated here requires a specific file path)
Any idea?
EDIT Dropbox actually recommends not automatically recursing via /metadata calls. (See https://www.dropbox.com/developers/core/bestpractices.)
There's no method to get a recursive list of files, so you would need to use /search to find files or /delta with no cursor to get the full list of files.
Could the Chooser be an option here (if you're just trying to let the user pick individual files)?