Problems with Google Picker API and selecting Google Drive items - google-drive-api

I am trying to integrate a Google Picker for selecting files from Google Drive following this example.
When opening the picker I get an error in the javascript console and the dialog prompts for a login.
Unable to post message to https://docs.google.com. Recipient has origin https://my-app.herokuapp.com.
When clicking the login button a popup opens and immediately closes again, but nothing happens.
When closing the dialog there is another error in the javascript console
Unknown RPC service: picker
I am not quite sure what causes these errors or even what to make of it.
Can somebody put me in the right direction?
EDIT
User is logged in to the app. Also, when using "Open with" menu on a file in the Google Drive interface and choose my application, I can access that file.

You have to add https://my-app.herokuapp.com to the list of authorized Javascript Origins in the APIs Console:
go to the APIs Console: https://code.google.com/apis/console/
select your project from the dropdown menu
open the tab API Access
click on Edit Settings for the Client ID for Web Applications section corresponding to your client
add the URI to the list of Authorized JavaScript Origins

Related

Chrome extension authorize in new tab

I'm trying to implement user authorization for chrome extension.
I want to open new tab, log in there and receive access token and next get back to extension tab to update options page (show user is logged).
I use chrome.identity.launchWebAuthFlow but it opens new window instead of tab as I'd like to.
I want to achieve login similar like in Pocket extension.
Do you have any suggestions?
Then you will need to forgo using the chrome.identity API. There is no such option.
Instead, you'll have to do magic with content scripts to extract the resulting token, and you might have some problems with regards to callback URL - you can no longer use the one provided by the identity API.

How do I launch a URL in a specific user instance of Chrome?

I'm looking to intercept a web request and launch that URL in another instance of Chrome. We have a Google Apps for Business account. And I regularly receive emails with Google Drive links. But they open in the last browser that had focus, which can be my personal user window. I'm looking to have Chrome get that web request, then either automatically open the link in the right window, or prompt for a choice. Is that possible?

Launching the Google Drive sharing dialog in an app. What should be the APP_ID value?

I'm following this article, trying to add a sharing dialog in a web app.
I got the button working in opening the modal popup, but it just prints this error in the console:
Refused to display 'https://drive.google.com/share?id=SOME_LONG_ID&foreignService=explorer&shareService=explorer&shareProtocolVersion=2&command=init&subapp=10&popupWindowsEnabled=true&shareUiType=default&rand=1386925457304&theme=2&client=postMessage&appId=MY_APP_ID&embedOrigin=http%3A%2F%2Fmy_app.appspot.com'
in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.
And the modal itself just shows the message "Sorry, sharing is unavailable at this time. Please try again later."
For the checklist at the bottom of the article:
The user is signed in to Google True
The user has installed your app False How do I ask them to install?
The URL of the page that launches the dialog must have the same origin as the Open URL registered for the app. True
So I have 2 questions:
How do I ask them to install my app? It's supposed to be a web app, where there's 1 button to select Drive files via the Picker API (which is now working), and then another button which will sow this Drive sharing dialog to set the permissions of the selected files. There's no need for installation. Will it work for this setup?
What should be the value for the APP_ID? I'm guessing it's the ID in the "Drive SDK" section of the Cloud Console? The console is so confusing and there's so many values for keys, ids, etc. that I have no idea which to use. Here's a screenshot of what I mean by the ID and what I'm trying to use.
(1) Installing means you have to get the user to accept the drive.install scope - instructions here. This will integrate your app with the "open with" menu in Google Drive. But before that can work you will need to tell the Google Cloud Console what url to go to when the user clicks "open" - more instructions. In your case, since you don't actually want to allow the user to open files from Drive you won't be defining any file types, so in reality there won't actually be any visible integration with Drive.
Note that the share dialog will only work on the one page which has the url you specify as the target for "open" (the instructions say this and from experience it seems to be true).
(2) Client ID You can find this in the Google Cloud Console - see above. Mine is a 12 digit number, so yours will probably be too.
I had the same problem. The iFrame error shows up when you call setItemIds if your app_id is wrong. No idea why. Anyway, it started working for me when I used the right app_id -- the one that shows up like in your screenshot.

Users are unable to open my Google Script web app

I have created an app script as an web app with doGet function. Its working fine with no issues. But when I am sending that link to my friends its opening the Google docs login page instead of UI.
The link I am giving to my friends is the one which is shown after clicking 'deploy as web app', is labeled as 'Current web app URL'. And at the pop up screen which pops when we click 'Deploy as web app' button, i set that anyone have access to the app and I am accessing the app as 'User accessing the app'.
Setting the access permission to Anyone means 'Anyone with a gmail or Google Apps account' and it is therefore they are required to sign in. HOwever, if you set it to Anyone including anonymous, your friends need not sign in.

What is the main difference with picker api and OAuth JS-example

google picker api doesnt force the user to an OAuth dialog, no asking them to authorize the application to upload or request active user data. In the quickstart guide "https://developers.google.com/drive/quickstart-js" there is a simple example to upload a file for active user .The user must accept the application. What is the main difference with picker api and OAuth JS-example.
Can I write a code like picker api for active user
I want to upload and list active user drive data without using picker api
The picker does two things which you can't do manually in a third-party application:
Uses cookie auth for the currently logged in Google user
Adds the file to the drive.file scope's opened with files, so an app with the file scope can access it.