Google Drive SDK: using drive.install scope to integrate web app into "open with" UI not working - google-drive-api

I have tried without much success to integrate my web application within the Google Drive UI (to open files). I cannot get the app to install using the OAuth scope https://www.googleapis.com/auth/drive.install.
I was wondering if anybody could share their Drive SDK configuration to see if I missed something. I tried installing my app using the Google API Console by selecting the Drive Integration to automatically authenticate. I also tried manually making the OAuth request using the google-api-client gem.
I always get the permissions dialog and I can see the following being requested: Add itself to Google Drive. I also get redirected back to my application like a normal OAuth request, but the application is never listed in Google Drive.
I have been requesting the following scopes:
https://www.googleapis.com/auth/drive.install
https://www.googleapis.com/auth/drive.file
profile
user
Allowing Import and these Secondary MIME Types:
application/vnd.google.drive.ext-type.html
text/html
I followed the documentation here: https://developers.google.com/drive/web/enable-sdk
Thanks in advance for any help!!

I was able to solve this by modifying my OAuth flow. It wasn't exchanging the authentication code for an access token before. Once I made it to that point everything worked as expected.

My issue was, that I didn't have this set:
Allowing Import and these Secondary MIME Types:
application/vnd.google.drive.ext-type.html text/html
I'm working with Google Spreadsheets, so I need a mime type that a sheet can be converted to, such as text/csv, see https://developers.google.com/drive/api/v3/integrate-open#open_and_convert_google_docs_in_your_app

Related

Sharing Google Drive Realtime Documents

I have created a realtime document on Google Drive. When I attempt to share this file with someone who doesn't have my app installed, the file shares successfully, but when they click the file it says "Sorry, no preview is available".
This realtime document is a shortcut file. How do I get it to prompt the person to authorize my app?
I'm using the Realtime Playground as my example as I'm not sure of the specifics of your application.
App authorisation
When you created your application you visited the Google API Console and created a project with Drive API enabled. At some point you copied "Client ID" from the Google API Console into you application ID code.
In the realtime-playground case APP_ID is set in the javascript file rtpg.js (you might not be using JavaScript but there will be an equivalent step for other languages).
rtpg.APP_ID = '840867953062';
File creation
I believe that any drive realtime document/shortcut you created with your application will contain a reference to the creating application (mostly likely in the form of the client/application ID you obtained above).
File sharing
Once you can see your newly created Google Drive Realtime document/shortcut you can share this with somebody else using the normal Google Drive sharing methods. At this point they can see it but cannot do anything apparently useful with it. This is where I believe your application may differ from the realtime-playground example.
Integration with Chrome Web Store
On the GitHub repository for realtime-playground you'll notice a cws (Chrome Web Store) directory containing the stuff necessary to deploy the realtime-playground as Google Drive application in the Chrome Store including screenshots to be used. If you look at the manifest.json file you will see another reference to the client id:
"api_console_project_id" : "840867953062"
So if I share a realtime-playground file with somebody who doesn't have it installed, then clicking on the file in Google Drive will result in a "Connect app" popup which will try to locate the corresponding Chrome Web Store Drive app (using the common id as the key) and this will show something similar to what you might see if you found this application directly in the Chrome Web Store.
The manifest.json also contains:
"app" : { "launch" : {
"web_url" : "https://realtimeplayground.appspot.com/" } }
which tells Google Drive what to do when the installed app is called.
So my guess is that your application doesn't work like this as you don't yet have public visibility of your app in the Chrome Web Store.
See also: Create a Chrome Web Store Listing
I hope this helps.
That is fine. If you open your eyes, you will notice that Playground demo does not provide any preview either
Yet, you see, the associated app is available. You can click it and open-with works normally. Your app-created files operate similarly. They are associated with your app by default. You can open them by open with rather than by preview. Can you? No, you cannot. But that is another question.
Otherwise, I see no cleverness in associating your file with chrome extension rather than with your app.
How do I get it to prompt the person to authorize my app?
I recently had a similar question. Instead of linking your files with extension in chrome, pass the direct link, like http://your-app#fileId=..., as playground demonstrates to your shared fellow if open-with fails.
The preview seems to be another story.
Wait, Do you mean that I need to create a new fresh account to test how your file is unassociated with your app? How do you preview the files in your primary account? If you know how to preview you may answer my question, at least partially. But why do you associate authorization with preview?

I'm trying to access Google Drive through the CLI, but keep getting "Not authorized to request the scopes"

I used to run a script that would back up various files and put them in my GDrive. Simple bash, really. By "putting them in GDrive" I mean it would simple move the files to ~/Google Drive/ which would be picked up by my laptop.
I'm trying to build a similar app that will upload certain files to my Google Drive. It should be started by me, save the auth details and then start uploading. This must also run from the command line. However, there is no Google Drive client that will pick up the files. I must upload the files myself.
Currently, I'm having trouble with the OAuth2 procedure. I've set up a project on cloud.google.com, I have the keys, the library ready and the scopes set up, but Google keeps refusing my request. I've enabled both the Drive API and the Drive SDK.
The error I'm getting is:
{
"error" : "invalid_scope",
"error_description" : "Not authorized to request the scopes: [https://www.googleapis.com/auth/drive]",
"error_uri" : "http://code.google.com/apis/accounts/docs/OAuth2.html"
}
No matter what I try, I cant get this scope to work. Other scopes work fine. Trying to find what could cause this is impossible, the Google searches I've tried are muddled.
These are the scopes I'm requesting:
https://www.googleapis.com/auth/drive
https://www.googleapis.com/auth/userinfo.email
https://www.googleapis.com/auth/userinfo.profile
What am I missing?
I've managed to get access using the following scope instead of https://www.googleapis.com/auth/drive:
https://docs.google.com/feeds
From the manual:
Full, permissive scope to access all of a user's files. Request this
scope only when it is strictly necessary. Tokens with scope
https://docs.google.com/feeds are accepted and treated the same as
tokens with scope https://www.googleapis.com/auth/drive.
I tried it, and it worked.
Are you sure you enable the API's for Google Drive API, Drive SDK, Google+? You have to do this in order to use those scopes from Google Developer Console

Confuse after quickstart

I am pretty new to Google Drive SDk. After spend hours on the google drive sdk document and quick start app, I think I have known some basic concepts about it.
However, I have a easy but crucial question: how to integrate my code with Drive UI.
I mean I know I should enable Google Drive API and Google Drive SDK and do some configure staff. And I did.
I set up the MIME type that my app should be able to open and create, but it doesn't work. (I used the most easy one: plain/text: txt).
In fact, I think this is not the most serious problem. I am confused about how to integrate my code with Drive UI.
I mean the quick start app works fine, but it just simply upload a file. What if I want to perform some complicate action after user open a certain file with my app?
Ideally, I think it should redirect the user to my open URL and all the actions should go with that site, right?
(I am using Python, in case that could make any differences)
I am really confused. Excuse my chaos description, please.
Thanks in advance!
EDIT:
Thanks for the answering below! I think I need to detailed explain my needs from google drive sdk.
Basically, I want the user who have installed my app be able to open a certain file (which should be spreadsheet or txt) on google drive. Then it will redirect the user to my given Open URL (which I create a site by using google site). On that site, user should be able to view and import the content of file into a certain database. None of the operations above require any technique knowledges. I certainly can do this by writing python script and run it locally to import the content of files on google drive. However, there are two issues: first, I need to run it locally. I mean I did use the google drive api, but I didn't explore the real benefit of api; second, it is still a command line script, and has to be ran on linux.
I hope I have illustrated my request. And I appreciate any help in advance!
Install the client library:
pip install --upgrade google-api-python-client
Acquire an access token as explained on the Python Quickstart example. Init a Drive service to be able to talk to the API and authorize http transporter with your credentials. You need to make requests to get file metadata and file contents.
Retrieve file metadata:
http = httplib2.Http()
http = credentials.authorize(http)
drive_service = build('drive', 'v2', http=http)
f = drive_service.files().get(fileId=file_id).execute()
Retrieve file contents:
downloadUrl = f.get('downloadUrl')
f['content'] = drive_service._http.request(downloadUrl)
(Don't forget content retrieving request should be authorized and authenticated, that's why we use drive_service._http to make that request.

App built using Google Drive PHP SDK keeps redirecting to the same page

I'm following this guide to create a sample web app which implements the Google Drive PHP SDK.
When I access the URL, the app keeps redirecting to the same page in an infinite loop, so no content is shown actually. Any idea why this is happening? Is it due to some mistake I made in the config file?
The document says how to implement the sample app - called DrEdit - as a Google Chrome application. Can anyone tell me if it is possible to use the SDK for creating non-Google Chrome apps? Also, does anyone have any example implementation of the Google Drive SDK?
If you provide more information and code, we can debug your first issue.
Otherwise:
Yes, you can write apps for Drive that are not Chrome apps. Chrome Web Store is an optional distribution mechanism for the API. Your apps will work in any browser.
There are documented PHP snippets for every API method, e.g. https://developers.google.com/drive/v1/reference/files/get

I am facing "The authenticated user has not installed the app with client id" error even after installing the app [duplicate]

I'm working on a Google Drive interface for Emacs. The concept is that Emacs could provide a platform-agnostic way to load, modify and save text documents stored in Google Drive. I've registered my app and can authenticate with OAuth2 and get a file listing with the Docs List API, but when I try to execute an Insert with the Google Drive API, I see an error:
"The authenticated user has not installed the app with client id ..."
Reading further, it seems I need to publish my Emacs application in the Chrome Web Store to get access to the Drive API. That doesn't make sense to me...I noticed that there is a FUSE project in development for Google Drive, which suggests that native development is possible. When I skimmed the code, however, I didn't see a Chrome Web Store component to getting it working.
Am I trying to misuse the API, or is there an route to make this work that makes more sense?
EDIT:
According to Ali Afshar, of the Google Drive team, installation is no longer required to use this API. So what follows may no longer be relevant, but will be left for historical purposes.
So, first off the API does not support application development in the sense that we are both doing it, I wouldn't use the word native though. The good news is I have been doing some research and Google Drive is really just a rebranding of Google Docs. So the Google Docs API could be a good choice as well for the same purposes.
Anyway, here's the steps to solve the error: "The authenticated user has not installed the app with client id ..." Which is a 403 error, for the sake of this answer. These steps assume you have set up an app in the chrome web store as is required, and installed it. I am working on my local machine too, with my project: http://github.com/tom-dignan/gdrive-cli which I have gotten past this error, so I think you should keep plugging away at your emacs version, because I think we can make this work.
a. Open the Google APIs console.
b. Confirm you've already enabled the apis under "API Access" both the API and SDK for Google drive should be enabled. There you get your client secrets/api keys and such. I am almost positive you've done this already, so go ahead to C. (this is here for others who may have missed it)
c. In the left navigation bar, under "Drive SDK" you will need to do the following:
Add a "Support URL" (required)
Add at least a small 16x16 application icon (required)
Add "OAuth Client ID (Required)" under Drive Integration (I was just tinkering and this seems to be the key field.)
Add "Open URL (Required) URL to open for your app from the google drive UI."
Check off "Multiple File Support"
Add some MIME types and file extensions, "text/plain", and txt for example
Add the the auth scopes:
https://www.googleapis.com/auth/userinfo.email
https://www.googleapis.com/auth/userinfo.profile
Don't bother trying to add the auth scopes for Google Docs here, because it won't work. Google does not want us to use it that way because files that drive apps create should be private to that app. Integration with Google Docs will have to be separate.
Now I know you must be thinking "why do I have to add some of these..." It's because the form makes them required fields. In mine, I put a couple URLs that point to static HTML pages.
Once you've done the above, clean up your state and reinstall your chrome app. Then try your code again, and it should stop giving you a 403.