Google Apps স্ক্রিপ্ট দ্রুত শুরু

একটি Google Apps স্ক্রিপ্ট তৈরি করুন যা Google Drive Activity API-তে অনুরোধ করে।

কুইকস্টার্টস ব্যাখ্যা করে যে কীভাবে একটি অ্যাপ সেট আপ এবং চালাতে হয় যা একটি Google Workspace API কল করে। এই কুইকস্টার্টটি একটি সরলীকৃত প্রমাণীকরণ পদ্ধতি ব্যবহার করে যা একটি পরীক্ষার পরিবেশের জন্য উপযুক্ত। একটি উৎপাদন পরিবেশের জন্য, আমরা আপনার অ্যাপের জন্য উপযুক্ত অ্যাক্সেস শংসাপত্রগুলি বেছে নেওয়ার আগে প্রমাণীকরণ এবং অনুমোদন সম্পর্কে শেখার পরামর্শ দিই।

অ্যাপস স্ক্রিপ্টে, গুগল ওয়ার্কস্পেস কুইকস্টার্টগুলি গুগল ওয়ার্কস্পেস এপিআই কল করতে এবং প্রমাণীকরণ এবং অনুমোদন প্রবাহের কিছু বিবরণ পরিচালনা করতে উন্নত গুগল পরিষেবা ব্যবহার করে।

উদ্দেশ্য

  • পরিবেশ কনফিগার করুন।
  • স্ক্রিপ্ট তৈরি এবং কনফিগার করুন।
  • স্ক্রিপ্টটি চালান।

পূর্বশর্ত

  • একটি গুগল অ্যাকাউন্ট
  • গুগল ড্রাইভে অ্যাক্সেস

স্ক্রিপ্ট তৈরি করুন

  1. script.google.com/create এ গিয়ে Apps Script এডিটরে একটি নতুন স্ক্রিপ্ট তৈরি করুন।
  2. স্ক্রিপ্ট এডিটরের বিষয়বস্তু নিম্নলিখিত কোড দিয়ে প্রতিস্থাপন করুন:

ড্রাইভ/অ্যাক্টিভিটি-ভি২/কুইকস্টার্ট.জিএস
/**
 * Lists 10 activity for a Drive user.
 * @see https://developers.google.com/drive/activity/v2/reference/rest/v2/activity/query
 */
function listDriveActivity() {
  const request = {
    pageSize: 10,
    // Use other parameter here if needed.
  };
  try {
    // Activity.query method is used Query past activity in Google Drive.
    const response = DriveActivity.Activity.query(request);
    const activities = response.activities;
    if (!activities || activities.length === 0) {
      console.log("No activity.");
      return;
    }
    console.log("Recent activity:");
    for (const activity of activities) {
      // get time information of activity.
      const time = getTimeInfo(activity);
      // get the action details/information
      const action = getActionInfo(activity.primaryActionDetail);
      // get the actor's details of activity
      const actors = activity.actors.map(getActorInfo);
      // get target information of activity.
      const targets = activity.targets.map(getTargetInfo);
      // print the time,actor,action and targets of drive activity.
      console.log("%s: %s, %s, %s", time, actors, action, targets);
    }
  } catch (err) {
    // TODO (developer) - Handle error from drive activity API
    console.log("Failed with an error %s", err.message);
  }
}

/**
 * @param {object} object
 * @return {string}  Returns the name of a set property in an object, or else "unknown".
 */
function getOneOf(object) {
  for (const key in object) {
    return key;
  }
  return "unknown";
}

/**
 * @param {object} activity Activity object.
 * @return {string} Returns a time associated with an activity.
 */
function getTimeInfo(activity) {
  if ("timestamp" in activity) {
    return activity.timestamp;
  }
  if ("timeRange" in activity) {
    return activity.timeRange.endTime;
  }
  return "unknown";
}

/**
 * @param {object} actionDetail The primary action details of the activity.
 * @return {string} Returns the type of action.
 */
function getActionInfo(actionDetail) {
  return getOneOf(actionDetail);
}

/**
 * @param {object} user The User object.
 * @return {string}  Returns user information, or the type of user if not a known user.
 */
function getUserInfo(user) {
  if ("knownUser" in user) {
    const knownUser = user.knownUser;
    const isMe = knownUser.isCurrentUser || false;
    return isMe ? "people/me" : knownUser.personName;
  }
  return getOneOf(user);
}

/**
 * @param {object} actor The Actor object.
 * @return {string} Returns actor information, or the type of actor if not a user.
 */
function getActorInfo(actor) {
  if ("user" in actor) {
    return getUserInfo(actor.user);
  }
  return getOneOf(actor);
}

/**
 * @param {object} target The Target object.
 * @return {string} Returns the type of a target and an associated title.
 */
function getTargetInfo(target) {
  if ("driveItem" in target) {
    const title = target.driveItem.title || "unknown";
    return `driveItem:"${title}"`;
  }
  if ("drive" in target) {
    const title = target.drive.title || "unknown";
    return `drive:"${title}"`;
  }
  if ("fileComment" in target) {
    const parent = target.fileComment.parent || {};
    const title = parent.title || "unknown";
    return `fileComment:"${title}"`;
  }
  return `${getOneOf(target)}:unknown`;
}

  1. সংরক্ষণ করুন ক্লিক করুন .
  2. Untitled project এ ক্লিক করুন, Quickstart টাইপ করুন এবং Rename এ ক্লিক করুন।

স্ক্রিপ্ট কনফিগার করুন

গুগল ড্রাইভ অ্যাক্টিভিটি এপিআই সক্ষম করুন

অ্যাপস স্ক্রিপ্ট প্রজেক্টটি খুলুন।

  1. এডিটর ক্লিক করুন।
  2. Services এর পাশে, Add a service ক্লিক করুন।
  3. ড্রাইভ অ্যাক্টিভিটি API নির্বাচন করুন এবং যোগ করুন এ ক্লিক করুন।

নমুনাটি চালান

অ্যাপস স্ক্রিপ্ট এডিটরে, রান এ ক্লিক করুন।

প্রথমবার যখন আপনি নমুনাটি চালাবেন, তখন এটি আপনাকে অ্যাক্সেস অনুমোদন করার জন্য অনুরোধ করবে:

  1. অনুমতি পর্যালোচনা করুন -এ ক্লিক করুন।
  2. একটি অ্যাকাউন্ট বেছে নিন।
  3. অনুমতি দিন ক্লিক করুন।

স্ক্রিপ্টের এক্সিকিউশন লগ উইন্ডোর নীচে প্রদর্শিত হবে।

পরবর্তী পদক্ষেপ