久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何使用 google drive api 使文件可共享

How to make the file shareable using google drive api(如何使用 google drive api 使文件可共享)
本文介紹了如何使用 google drive api 使文件可共享的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在嘗試使用 google drive api 獲取文件,默認(rèn)情況下該文件不可共享,我希望將其設(shè)為可共享.

I am trying to get the file using google drive api, by default the file is not shareable i want to make it shareable.

這是我的代碼:-

    <script type="text/javascript" src="https://apis.google.com/js/api.js"></script>
<script src="https://apis.google.com/js/client.js"></script>
        // The Browser API key obtained from the Google Developers Console.
            // Replace with your own Browser API key, or your own key.
            var developerKey = 'XXXXXXXXXX_ff_NX66eb-XXXXXXXXXXX';

            // The Client ID obtained from the Google Developers Console. Replace with your own Client ID.
            var clientId = "XXXXXXXXXX-hs4ujaro5sc3d0g8qndtcq2tl279cfm1.apps.googleusercontent.com"

            // Replace with your own App ID. (Its the first number in your Client ID)
            var appId = "XXXXXXXXXX";
            // Scope to use to access user's Drive items.
            var scope = ['https://www.googleapis.com/auth/drive'];

            var pickerApiLoaded = false;
            var oauthToken;

                  $scope.addGoogleDriveFile = function() {
                    gapi.load('auth', {'callback': onAuthApiLoad});
                     gapi.load('picker', {'callback': onPickerApiLoad}); 
                    gapi.client.setApiKey(developerKey);     
                      }

        function onAuthApiLoad() {
                         window.gapi.auth.authorize(
                             {
                               'client_id': clientId,
                               'scope': scope,
                               'immediate': false
                             },
                             handleAuthResult);
                       }

                        function onPickerApiLoad() {
                          pickerApiLoaded = true;
                          createPicker();
                        }

                        function handleAuthResult(authResult) {
                          if (authResult && !authResult.error) {
                            oauthToken = authResult.access_token;
                            createPicker();
                          }
                        }

                        // Create and render a Picker object for searching images.
                        function createPicker() {
                          if (pickerApiLoaded && oauthToken) {
                            var view = new google.picker.View(google.picker.ViewId.DOCS);
                            var picker = new google.picker.PickerBuilder()
                                .enableFeature(google.picker.Feature.NAV_HIDDEN)
                                .setAppId(appId)
                                .setOAuthToken(oauthToken)
                                .addView(view)
                                .addView(new google.picker.DocsUploadView())
                                .setDeveloperKey(developerKey)
                                .setCallback(pickerCallback)
                                .build();
                             picker.setVisible(true);
                          }
                        }

                    // A simple callback implementation.
                    function pickerCallback(data) {
                      if (data.action == google.picker.Action.PICKED) {
                          console.log(data);
                       gapi.client.load('drive', 'v2').then(function() {
                            var request = gapi.client.drive.files.get({
                            'fileId': data.docs[0].id
                          });   
                           request.execute(function(resp) {
                             console.log(resp);
                          }); 
               });

                      }
                    }

我收到以下回復(fù):-

{
 "kind": "drive#file",
 "id": "0B2Tb9btqdPGHeDl2NU5mYXRIaGc",
 "etag": ""rCKCAyesbPCaBxGt0eDJcEBQNUI/MTQ1ODgxNDU0MDg2NA"",
 "selfLink": "https://www.googleapis.com/drive/v2/files/0B2Tb9btqdPGHeDl2NU5mYXRIaGc",
 "webContentLink": "https://docs.google.com/uc?id=0B2Tb9btqdPGHeDl2NU5mYXRIaGc&export=download",
 "alternateLink": "https://drive.google.com/file/d/0B2Tb9btqdPGHeDl2NU5mYXRIaGc/view?usp=drivesdk",
 "iconLink": "https://ssl.gstatic.com/docs/doclist/images/icon_12_pdf_list.png",
 "thumbnailLink": "https://lh6.googleusercontent.com/iriNEeCbpP3OfCxntpc7sK7Dok03tcBJ86X4Be_sFgLXXG1Ta8b2WOM6pF6sEpS8ytaMvA
=s220",
 "title": "POTSS-2012.pdf",
 "mimeType": "application/pdf",
 "labels": {
  "starred": false,
  "hidden": false,
  "trashed": false,
  "restricted": false,
  "viewed": true
 },
 "createdDate": "2016-03-24T09:57:00.978Z",
 "modifiedDate": "2016-03-24T10:15:40.864Z",
 "modifiedByMeDate": "2016-03-24T09:57:00.978Z",
 "lastViewedByMeDate": "2016-03-24T09:57:00.978Z",
 "markedViewedByMeDate": "1970-01-01T00:00:00.000Z",
 "version": "130",
 "parents": [
  {
   "kind": "drive#parentReference",
   "id": "0AGTb9btqdPGHUk9PVA",
   "selfLink": "https://www.googleapis.com/drive/v2/files/0B2Tb9btqdPGHeDl2NU5mYXRIaGc/parents/0AGTb9btqdPGHUk9PVA"
,
   "parentLink": "https://www.googleapis.com/drive/v2/files/0AGTb9btqdPGHUk9PVA",
   "isRoot": true
  }
 ],
 "downloadUrl": "https://doc-0o-3g-docs.googleusercontent.com/docs/securesc/79n10ihd7kdei03rpq502qv5437nv33f
/b6p7kupn55cuqeqq8l0d9vc1orf4bkiv/1458813600000/07489391032112366212/07489391032112366212/0B2Tb9btqdPGHeDl2NU5mYXRIaGc
?e=download&gd=true",
 "userPermission": {
  "kind": "drive#permission",
  "etag": ""rCKCAyesbPCaBxGt0eDJcEBQNUI/QKpDIyepJ3z6YHq0L3ksgvrZLSo"",
  "id": "me",
  "selfLink": "https://www.googleapis.com/drive/v2/files/0B2Tb9btqdPGHeDl2NU5mYXRIaGc/permissions/me"
,
  "role": "owner",
  "type": "user"
 },
 "originalFilename": "POTSS-2012.pdf",
 "fileExtension": "pdf",
 "md5Checksum": "5b60cd94d0c0647c8828a60b8ce7efe4",
 "fileSize": "519097",
 "quotaBytesUsed": "519097",
 "ownerNames": [
  "xxxxx IT"
 ],
 "owners": [
  {
   "kind": "drive#user",
   "displayName": "xxxx IT",
   "isAuthenticatedUser": true,
   "permissionId": "07489391032112366212",
   "emailAddress": "it%xxxx .com@xxxxx.com"
  }
 ],
 "lastModifyingUserName": "xxxxx IT",
 "lastModifyingUser": {
  "kind": "drive#user",
  "displayName": "xxxx IT",
  "isAuthenticatedUser": true,
  "permissionId": "07489391032112366212",
  "emailAddress": "it%xxxx.com@xxxx.com"
 },
 "editable": true,
 "copyable": true,
 "writersCanShare": true,
 "shared": false,
 "explicitlyTrashed": false,
 "appDataContents": false,
 "headRevisionId": "0B2Tb9btqdPGHT0pGV1FRRis0MmlJVmZsOE5uMU5UK2FNR0g0PQ",
 "spaces": [
  "drive"
 ]
}

這里我想更改 "shared": true 而不是 "shared": false

Here i want to change "shared": true Instead of "shared": false

如何更改其權(quán)限?

有什么想法嗎?

謝謝

推薦答案

@arun 你可能想了解更多關(guān)于 權(quán)限資源."shared"true,每個文件權(quán)限需要指定一個roletype電子郵件地址或域.作為文件(文檔、表格等)的所有者,您需要提供要設(shè)置的適當(dāng)權(quán)限.

@arun you may want to read more about Permission resource in Drive API. For "shared" to be true, each file permission needs to specifies a role, type, and email address or domain. As an owner of the file (Docs, Sheets, etc.), you will need to provide the appropriate permission to be set to.

這是一個示例,使用 Permissions.create(我推薦使用 Drive API v3)

Here is an example, using the Permissions.create (I recommend using Drive API v3)

POST https://www.googleapis.com/drive/v3/files/{fileId}/permissions?key={YOUR_API_KEY}

{
 "role": "reader",
 "type": "user",
 "emailAddress": "xxxxxxxx@xxx.com"
}

來自云端硬盤的響應(yīng)Files.get:

GET https://www.googleapis.com/drive/v3/files/{fileId}?fields=appProperties%2CfileExtension%2Ckind%2CmimeType%2Cshared&key={YOUR_API_KEY}


{
 "kind": "drive#file",
 "mimeType": "application/vnd.google-apps.document",
 "shared": true
}

但是,如果您無法切換到 Drive v3,您仍然可以使用 Permission.insert 從 Drive v2 來完成這項工作.希望這對您有所幫助并祝您好運(yùn)!

However, if you are unable to switch to the Drive v3, you can still use the Permission.insert from Drive v2 to do the job. Hope this helpful and good luck!

這篇關(guān)于如何使用 google drive api 使文件可共享的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機(jī)器人提及發(fā)出該機(jī)器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復(fù)必須使用導(dǎo)入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務(wù)器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復(fù)“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務(wù)器時的歡迎消息)
主站蜘蛛池模板: 日日操天天射 | 一级毛片高清 | 欧美www在线观看 | 国产一区二区成人 | 亚洲精品成人在线 | 三级黄色大片网站 | 91在线看视频 | 99九色| 国产aaaaav久久久一区二区 | 国产91av视频在线观看 | www.操.com | 欧美视频精品 | 国内精品久久久久 | 日韩欧美综合在线视频 | 日韩精品一区二区三区视频播放 | 久久亚洲一区二区 | 99久久久久久99国产精品免 | 日本色综合 | 国产成人精品一区二 | www.青青草 | 精一区二区| 欧日韩不卡在线视频 | 精品国产91 | 国产伦精品一区二区三区照片91 | 欧美专区日韩专区 | 国产一区视频在线 | 欧美久久久网站 | 免费在线观看一区二区 | 蜜桃在线视频 | av第一页| 一区二区中文 | 免费观看毛片 | 日韩日韩日韩日韩日韩日韩日韩 | 亚洲日本欧美日韩高观看 | 嫩草影院网址 | 999免费网站 | 欧洲成人午夜免费大片 | 日韩和的一区二在线 | 在线观看深夜视频 | 欧洲精品码一区二区三区免费看 | 成人av一区|