简体   繁体   中英

Google Drive JavaScript SDK - Share Dialog Not Working

I have an application ( POARDS ) set up using the Google Drive SDK.

I am mainly processing this application's data in PHP, but a few features (such as the share dialog) use the JavaScript API.

<script type="text/javascript" src="https://apis.google.com/js/api.js"></script>
<script type="text/javascript">
    init = function() {
        s = new gapi.drive.share.ShareClient('737617002551');
        s.setItemIds(["ncle837jp4berdbjftouwixsjub1fvt2"]);
    }
    window.onload = function() {
        gapi.load('drive-share', init);
    }
</script>

The issue is that when I try to launch the share dialog using s.showSettingsDialog(); the sharing system malfunctions. A blank modal with a loading message pops up, and after a few seconds, I recieve the following error message:

Sorry, sharing is unavailable at this time. Please try again later.

Upon further investigation, an error message in the development console is also available:

Refused to display ' https://drive.google.com/share …' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'

The message appears twice: once when the gapi.load(); call is made, and again when the s.showSettingsDialog(); call is made. In the Google documentation, it says that the share modal only has three requirements:

  1. The user is signed in to Google
  2. The user has installed your app
  3. The URL of the page that launches the dialog must have the same origin as the Open URL registered for the app.

However, as far as I can tell, my application matches these three rules. Thus, the dialog should appear like normal.

Share dialog has strict requirements related to Content Security Policy. Your application must follow those strict requirements. Any deviation will cause issues like this with the Share dialog.

This link may assist you in further understanding those requirements: https://developer.chrome.com/extensions/contentSecurityPolicy

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM