如何使用" Google云端硬盘文件选择器" API获取"共享URL"和"管理权限"对于文件?

时间:2016-03-23 07:49:42

标签: php api permissions google-drive-api

我想使用" Google Drive文件选择器" API获取"共享URL"和"管理权限"的文件。

我在这里找到了例子" http://stuff.dan.cx/js/filepicker/google/"显示文件列表但不确定如何管理文件和获取共享URL的权限。

以下是我的代码

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>Google Drive File Picker Example</title>
</head>
<body>
    <div style="color:#ff0000; display: none;" id="error_file"> File is not shared. </div>
        <input type="text" id="file_url" value="" class="form-control" name="settings[url]">
    <button type="button" id="pick">Pick File</button>
    <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();
                s.setOAuthToken('OAUTH_TOKEN');
                s.setItemIds(['FILE_ID']);
            }
            window.onload = function() {
                auth();
                gapi.load('drive-share', init);
            }
        </script>
        <button onclick="s.showSettingsDialog()">Share</button>

    <script src="filepicker.js"></script>
    <script>
        function initPicker() {
            var picker = new FilePicker({
                apiKey: 'AIzaSyB8a8yohsAyEz1eZEFgt2YE-tMgACYWnVs',
                clientId: '458068379722',
                buttonEl: document.getElementById('pick'),
                onSelect: function(file) {
                    console.log(file);                                       
                                        document.getElementById('file_url').value = file.embedLink;

                                        alert('Shared ' + file.shared);
                                        if(file.shared){
                                            alert('Share URL ' + file.embedLink);
                                        }else{                                            
                                            document.getElementById('error_file').style.display = 'block';
                                            document.getElementById('file_url').value = '';
                                        }

                }
            }); 
        }
    </script>

    <script src="https://www.google.com/jsapi?key=AIzaSyDbxa43P60iZSNUlFEquVrHV3Ir0H3FDI4"></script>
    <script src="https://apis.google.com/js/client.js?onload=initPicker"></script>
</body>
</html>

我能够跟踪文件是否共享但无法管理权限。任何人都可以帮我解决这个问题。

由于

0 个答案:

没有答案