Share files with Google Drive SDK

I've been following Google's documentation to share files on Drive: Share Files

If I upload a file to Google Drive from the Google Drive interface, then try to share this file from my webapp, i get the following error in my javascript console:

in chrome:

Refused to display 'https://drive.google.com/share?id=0B6UmN_AivG7SLWVYakF2Rk1CdDg&foreignServi…=postMessage&appId=958414147877&embedOrigin=http%3A%2F%2Fsandbox.velop.org' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'. 

in firefox:

[14:04:41.157] Load denied by X-Frame-Options: https://drive.google.com/share?id=0B6UmN_AivG7SLWVYakF2Rk1CdDg&foreignService=explorer&shareService=explorer&shareProtocolVersion=2&command=init&subapp=10&popupWindowsEnabled=true&shareUiType=default&rand=1370585078609&theme=2&client=postMessage&appId=958414147877&embedOrigin=http%3A%2F%2Fsandbox.velop.org does not permit cross-origin framing.

Now the weird thing is if I create the file from my webapp and upload to Drive through the api, I am able to share the file without problem.

Even stranger, it is enough that I open the file once from within Drive ( I have installed the webapp in my Drive so I can open files using my webapp) to be able to share it, even if later I don't use Drive to open the file anymore.

Any idea what could be causing this kind of behavior?

In my Drive SDK console, I set the Open URL to: http://sandbox.velop.org/my-google-drive/detail

When I open the file in Drive using my webapp, Drive thus redirects me to: http://sandbox.velop.org/my-google-drive/detail?state=%7B%22ids%22:%5B%220B6UmN_AivG7SLWVYakF2Rk1CdDg%22%5D,%22action%22:%22open%22,%22userId%22:%22105908447865504163566%22%7D (able to share)

When I open a file in my webapp, the URL is like: http://sandbox.velop.org/my-google-drive/0B6UmN_AivG7SLWVYakF2Rk1CdDg/detail (able to share only if opened from drive once before)

EDIT:

I realized this is the standard behavior for Google Drive API as described here:

When users approve these scopes, the app is installed for the user, with access to files that the user creates or opens with the app.

Is there a way to allow the app to open / write any file?

I thought that using the https://www.googleapis.com/auth/drive scope when registering my app would allow me to do this, but doesn't seem to be the case..

Answers:

Answer

I am running into exactly the same issue.

My app is requesting the full drive scope (so the app should have access to all files). But sharing only works if the file has been opened by the user from the drive before. There seems to be some magic "while-listing" of files that have been opened from drive.

When accessing a file that has not been opened from drive before I get...

Refused to display htps://drive.google.com/share?id=0534534543iTEhYamxfUnc2MnM&foreignServi…ent=postMessage&appId=46459361793&embedOrigin=http%3A%2F%2Fwww.editey.com' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

...which obviously is misleading as the share button is not in a frame.

Opening the give url in a new browser tab gives a hint to the real root-cause: Application '3453459361793' is not authorized to access document "0B0o5345345DAc_SiTEhYamxfUnc2MnM".

My app should have access to the document but it looks as if the "share dialog" acts as a separate app that will only allow access to files that have previsouly been opened from drive.

Answer

For security reasons drive will not let you use that dialog unless you're at the URL specified in by your "Open URL".

Your current URL http://sandbox.velop.org/my-google-drive/0B6UmN_AivG7SLWVYakF2Rk1CdDg/detail != http://sandbox.velop.org/my-google-drive/detail

So you might want to change your URL structure. Maybe something like http://sandbox.velop.org/my-google-drive/detail?open=B6UmN_AivG7SLWVYakF2Rk1CdDg

This is real pain in the neck, especially when developing on a different domain.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.