I want to create a google drive add-on, which can right click on a .dwg file then view it with pure web. So user don’t have to install AutoCAD to open the file.
I use google pick to pick a file, then need to request the file content to browser then view it with my js sdk. My app is deployed at (URL Removed by Staff).
It seems that I cannot use drive.readonly scope, which is restricted scope. “drive.file“ should be ok to view and update the file. I only need to view it, won’t update the file. But when I use following code to fetch the file, I always get 404 error (which should be 403 actually). If I change to use drive.readonly, I can get the file correctly, but google said I cannot use that one.
Hi @Yan_Zexuan With drive.file you can only access files your app created or files the user explicitly opened with your app if you just pick a file that was not opened via your Drive app Google returns 404 by design to hide the file you must implement Open with integration and ensure the same OAuth token with drive.file scope is used in both Picker and the fetch request then files.get with alt=media will work without needing drive.readonly
Thanks a lot! But I’m still a bit confusing. My app is a viewer, it doesn’t create or update file. Here is a video showing how it works: (URL Removed by Staff) .
I beleive that I used the same OAuth token and scope with google picker and the fetch request. My app firstly ask user to connect to google drive, then I can get token with gapi.client.getToken(), then pass to Picker and files.get. And, still doesn’t work!
@Yan_Zexuan With drive.file your app can only download files that were explicitly opened with your app through Drive Open with integration not just selected in Picker
Picker selection alone does not grant download permission under drive.file even if you use the same token this is why Drive returns 404 by design
Since your app is a viewer you must configure it as a Drive app with an Open with entry in Google Cloud Console and ensure the file is opened from Drive into your app not only picked
If you do not want to implement Open with then drive.readonly is required but that scope is restricted and needs verification
So the issue is not the token handling your flow must start from Drive Open with for drive.file to work properly