Google Drive में एकाधिक उपयोगकर्ताओं के साथ फ़ाइलें साझा करने का तरीका जानें

हेलो दोस्तों आज मैं आपको सिखाऊंगा कि कैसे एक से अधिक यूजर्स के साथ Google Drive में फाइल्स को आसान तरीके से शेयर करें। तो चलिए आज के कोड स्निपेट के साथ शुरुआत करते हैं। अलग-अलग समस्याओं को प्राप्त करना पूरी तरह से एक बहुत ही अलग अनुभव देता है। आज मैं आपके साथ जो कोड स्निपेट साझा करने जा रहा हूं, वह है कि Google Drive में फ़ाइलों को एकाधिक उपयोगकर्ताओं के साथ आसान तरीके से कैसे साझा किया जाए।

Google Drive में एकाधिक उपयोगकर्ताओं के साथ फ़ाइलें साझा करने का तरीका जानें

ऐप्स स्क्रिप्ट की सहायता से,Google Drive API प्रोग्राम के रूप में अन्य उपयोगकर्ताओं के साथ फ़ाइलों और फ़ोल्डरों को साझा करना आसान बनाता है।

उदाहरण के लिए, यहां कुछ कोड दिया गया है जो आपको फ़ाइल को किसी अन्य Google खाता उपयोगकर्ता के साथ साझा करने और उन्हें फ़ाइल में संपादन एक्सेस प्रदान करने की अनुमति देगा। उन्हें केवल पढ़ने के लिए पहुँच प्रदान करने के लिए, लेखक से पाठक के रूप में उनकी भूमिका बदलें।

आपको हमारे ट्रेंडिंग कोड स्निपेट भी पसंद आ सकते हैं

const shareFilesInGoogleDrive = (fileOrFolderId, emailAddress) => {
  Drive.Permissions.insert(
    {
      role: "writer", // or "reader" or "commenter"
      value: emailAddress,
      type: "user",
    },
    fileOrFolderId,
    {
      supportsAllDrives: true,
      sendNotificationEmails: true,
    }
  );
};

It is recommended that you set the sendNotifications flag to true as it will send an email notification when the file is shared with a user who may not have a Google account.

एकाधिक उपयोगकर्ताओं के साथ फ़ाइलें कैसे साझा करें

डिस्क API की एक सीमा यह है कि आप एक समय में केवल एक उपयोगकर्ता के साथ फ़ाइलें साझा कर सकते हैं। Google Apps स्क्रिप्ट समकालिक है – यह जावास्क्रिप्ट वादों के async/प्रतीक्षा पैटर्न का समर्थन नहीं करता है और इसलिए आप समानांतर में कोड नहीं चला सकते हैं।

There’s however a simple workaround to help you share a file or folder in Google Drive with multiple users in one go in parallel using the UrlFetchApp service.

const shareGoogleDriveFileWithMultipleUsers = () => {
  const fileId = "<Drive File Id>";
  const editors = ["angus@gmail.com", "kiran@school.edu", "jacob@corp.com"];

  const API = "https://www.googleapis.com/drive/v3/files";
  const queryString = "supportsAllDrives=true&sendNotifications=true";
  const accessToken = ScriptApp.getOAuthToken();

  const requests = editors.map((emailAddress) => ({
    url: `${API}/${fileId}/permissions?${queryString}`,
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${accessToken}`,
    },
    muteHttpExceptions: true,
    payload: JSON.stringify({
      role: "writer",
      type: "user",
      emailAddress: emailAddress,
    }),
  }));

  UrlFetchApp.fetchAll(requests);
};

ऊपर दिए गए स्निपेट में, हम सीधे ऐप स्क्रिप्ट की DriveApp सेवा के बजाय Google Drive API (v3) का उपयोग कर रहे हैं। FetchAll आपको एक ही अनुरोध में कई HTTP अनुरोध करने की अनुमति देता है और प्रतिक्रियाओं की एक श्रृंखला देता है।

Please ensure that the following scopes are added in your appsscript.json file:

  {
    ...
    "oauthScopes": [
      "https://www.googleapis.com/auth/script.external_request",
      "https://www.googleapis.com/auth/drive",
    ],
   ...
  }

अगर यह आपकी मदद करता है तो कृपया इसे अपने दोस्त के साथ भी साझा करें, जिसे मदद की ज़रूरत है क्योंकि आपका एक शेयर हमें बहुत धन्यवाद दे सकता है।

Leave a Comment