Google Drive गतिविधि सेवा
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
Google Drive Activity सेवा की मदद से, Apps Script में Google Drive Activity API का इस्तेमाल किया जा सकता है. इस एपीआई की मदद से, उपयोगकर्ता प्रोग्राम के हिसाब से Google Drive में की गई अपनी गतिविधि की जानकारी पा सकते हैं.
रेफ़रंस
इस सेवा के बारे में ज़्यादा जानकारी के लिए, Google Drive Activity API के रेफ़रंस दस्तावेज़ देखें. Apps Script की सभी ऐडवांस सेवाओं की तरह, Google Drive Activity सेवा भी सार्वजनिक एपीआई के ऑब्जेक्ट, तरीकों, और पैरामीटर का इस्तेमाल करती है. ज़्यादा जानकारी के लिए, तरीके के सिग्नेचर कैसे तय किए जाते हैं लेख पढ़ें.
समस्याओं की शिकायत करने और अन्य सहायता पाने के लिए, Google Drive में गतिविधि से जुड़ी सहायता गाइड देखें.
नमूना कोड
नीचे दिए गए सैंपल कोड में, एपीआई के वर्शन 2 का इस्तेमाल किया गया है.
Google Drive में गतिविधि की जानकारी पाना
इस सैंपल से, उपयोगकर्ता की Google Drive में हुई हाल ही की गतिविधि की जानकारी मिलती है. साथ ही, हर गतिविधि के समय, गतिविधि करने वाले व्यक्ति, गतिविधि, और गतिविधि के टारगेट के बारे में जानकारी मिलती है.
जब तक कुछ अलग से न बताया जाए, तब तक इस पेज की सामग्री को Creative Commons Attribution 4.0 License के तहत और कोड के नमूनों को Apache 2.0 License के तहत लाइसेंस मिला है. ज़्यादा जानकारी के लिए, Google Developers साइट नीतियां देखें. Oracle और/या इससे जुड़ी हुई कंपनियों का, Java एक रजिस्टर किया हुआ ट्रेडमार्क है.
आखिरी बार 2025-08-31 (UTC) को अपडेट किया गया.
[null,null,["आखिरी बार 2025-08-31 (UTC) को अपडेट किया गया."],[[["\u003cp\u003eThe Google Drive Activity service enables programmatic access to Google Drive activity data using the Google Drive Activity API within Apps Script.\u003c/p\u003e\n"],["\u003cp\u003eThis advanced service requires enabling before use and mirrors the functionality of the public API, using the same objects, methods, and parameters.\u003c/p\u003e\n"],["\u003cp\u003eComprehensive reference documentation, support resources, and sample code are available to guide developers in utilizing this service effectively.\u003c/p\u003e\n"],["\u003cp\u003eThe provided sample code demonstrates retrieving and logging recent Drive activity, including time, actor, action, and target information, using version 2 of the API.\u003c/p\u003e\n"]]],[],null,["# Google Drive Activity Service\n\nThe Google Drive Activity service allows you to use the\n[Google Drive Activity API](/drive/activity) in Apps Script. This API\nallows users programmatic access to retrieve information about their Google Drive activity.\n| **Note:** This is an advanced service that must be [enabled before use](/apps-script/guides/services/advanced).\n\nReference\n---------\n\nFor detailed information on this service, see the\n[reference documentation](/drive/activity/v2/reference/rest) for the Google\nDrive Activity API. Like all advanced services in Apps Script, the Google Drive Activity service uses the same objects, methods, and parameters as the\npublic API. For more information, see [How method signatures are determined](/apps-script/guides/services/advanced#how_method_signatures_are_determined).\n\nTo report issues and find other support, see the\n[Google Drive Activity support guide](/drive/activity/v2/support).\n\nSample code\n-----------\n\nThe sample code below uses [version 2](/drive/activity/v2) of\nthe API.\n\n### Get activity in Google Drive\n\nThis sample gets recent activity in a user's Google Drive and logs information about the time, actor, action, and target of each activity. \ndrive/activity-v2/quickstart.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/drive/activity-v2/quickstart.gs) \n\n```javascript\n/**\n * Lists 10 activity for a Drive user.\n * @see https://developers.google.com/drive/activity/v2/reference/rest/v2/activity/query\n */\nfunction listDriveActivity() {\n const request = {\n pageSize: 10\n // Use other parameter here if needed.\n };\n try {\n // Activity.query method is used Query past activity in Google Drive.\n const response = DriveActivity.Activity.query(request);\n const activities = response.activities;\n if (!activities || activities.length === 0) {\n console.log('No activity.');\n return;\n }\n console.log('Recent activity:');\n for (const activity of activities) {\n // get time information of activity.\n const time = getTimeInfo(activity);\n // get the action details/information\n const action = getActionInfo(activity.primaryActionDetail);\n // get the actor's details of activity\n const actors = activity.actors.map(getActorInfo);\n // get target information of activity.\n const targets = activity.targets.map(getTargetInfo);\n // print the time,actor,action and targets of drive activity.\n console.log('%s: %s, %s, %s', time, actors, action, targets);\n }\n } catch (err) {\n // TODO (developer) - Handle error from drive activity API\n console.log('Failed with an error %s', err.message);\n }\n}\n\n/**\n * @param {object} object\n * @return {string} Returns the name of a set property in an object, or else \"unknown\".\n */\nfunction getOneOf(object) {\n for (const key in object) {\n return key;\n }\n return 'unknown';\n}\n\n/**\n * @param {object} activity Activity object.\n * @return {string} Returns a time associated with an activity.\n */\nfunction getTimeInfo(activity) {\n if ('timestamp' in activity) {\n return activity.timestamp;\n }\n if ('timeRange' in activity) {\n return activity.timeRange.endTime;\n }\n return 'unknown';\n}\n\n/**\n * @param {object} actionDetail The primary action details of the activity.\n * @return {string} Returns the type of action.\n */\nfunction getActionInfo(actionDetail) {\n return getOneOf(actionDetail);\n}\n\n/**\n * @param {object} user The User object.\n * @return {string} Returns user information, or the type of user if not a known user.\n */\nfunction getUserInfo(user) {\n if ('knownUser' in user) {\n const knownUser = user.knownUser;\n const isMe = knownUser.isCurrentUser || false;\n return isMe ? 'people/me' : knownUser.personName;\n }\n return getOneOf(user);\n}\n\n/**\n * @param {object} actor The Actor object.\n * @return {string} Returns actor information, or the type of actor if not a user.\n */\nfunction getActorInfo(actor) {\n if ('user' in actor) {\n return getUserInfo(actor.user);\n }\n return getOneOf(actor);\n}\n\n/**\n * @param {object} target The Target object.\n * @return {string} Returns the type of a target and an associated title.\n */\nfunction getTargetInfo(target) {\n if ('driveItem' in target) {\n const title = target.driveItem.title || 'unknown';\n return 'driveItem:\"' + title + '\"';\n }\n if ('drive' in target) {\n const title = target.drive.title || 'unknown';\n return 'drive:\"' + title + '\"';\n }\n if ('fileComment' in target) {\n const parent = target.fileComment.parent || {};\n const title = parent.title || 'unknown';\n return 'fileComment:\"' + title + '\"';\n }\n return getOneOf(target) + ':unknown';\n}\n```"]]