অনুমোদনের সুযোগ

Users must authorize script projects that access their data or act on their behalf. For a high-level overview of this process, see Authorization for Google Services . When a user runs a script that requires authorization for the first time, the UI presents a prompt to start the authorization flow.

During this flow, the UI tells users which permissions the script requests. For example, a script might request permission to read email messages or create calendar events. The script project defines these individual permissions as OAuth scopes .

For most scripts, Apps Script automatically detects required scopes. You can view the scopes a script uses at any time. You can also set scopes explicitly in your manifest using URL strings. Published applications, such as add-ons , must use the narrowest scopes possible.

During the authorization flow, Apps Script presents human-readable descriptions of the required scopes. For example, if your script needs read-only access to spreadsheets, the manifest might include the scope https://www.googleapis.com/auth/spreadsheets.readonly . The authorization prompt asks the user to "View your Google Spreadsheets".

কিছু স্কোপের মধ্যে অন্যান্য স্কোপও অন্তর্ভুক্ত। উদাহরণস্বরূপ, https://www.googleapis.com/auth/spreadsheets এ অনুমোদিত অ্যাক্সেস স্প্রেডশিটগুলিতে পড়ার এবং লেখার অ্যাক্সেসের অনুমতি দেয়।

For some surfaces, such as the Apps Script IDE, users see the granular OAuth consent screen. This screen lets users select specific permissions to grant rather than granting all permissions at once. Design your script to handle granular OAuth permissions .

স্কোপ দেখুন

আপনার স্ক্রিপ্ট প্রকল্পের জন্য প্রয়োজনীয় স্কোপগুলি দেখতে:

  1. Open the script project.
  2. বাম দিকে, ওভারভিউ ক্লিক করুন।
  3. Project OAuth Scopes এর অধীনে স্কোপগুলি দেখুন।

স্পষ্ট সুযোগ সেট করুন

Apps Script automatically determines required scopes by scanning the code for function calls. While this is sufficient for most scripts, you must exercise more direct control for published add-ons, web apps, Chat apps, and calls to the Chat API.

Apps Script sometimes automatically assigns permissive scopes. This can mean your script asks users for more access than it needs. For published scripts, replace broad scopes with a limited set that covers the script's needs.

আপনার স্ক্রিপ্ট প্রজেক্টের ম্যানিফেস্ট ফাইল সম্পাদনা করে আপনি স্পষ্টভাবে স্কোপগুলি সেট করতে পারেন। oauthScopes ম্যানিফেস্ট ফিল্ড হল প্রজেক্ট দ্বারা ব্যবহৃত স্কোপগুলির একটি অ্যারে। আপনার প্রজেক্টের স্কোপগুলি সেট করতে:

  1. স্ক্রিপ্ট প্রজেক্টটি খুলুন।
  2. বাম দিকে, Project Settings ক্লিক করুন।
  3. এডিটর চেকবক্সে "appsscript.json" ম্যানিফেস্ট ফাইল দেখান নির্বাচন করুন।
  4. বাম দিকে, এডিটর ক্লিক করুন।
  5. বাম দিকে, appsscript.json ফাইলটিতে ক্লিক করুন।
  6. oauthScopes লেবেলযুক্ত শীর্ষ-স্তরের ক্ষেত্রটি খুঁজুন। যদি এটি উপস্থিত না থাকে, তাহলে আপনি এটি যোগ করতে পারেন।
  7. oauthScopes অ্যারের বিষয়বস্তুগুলিকে সেই স্কোপগুলি দিয়ে প্রতিস্থাপন করুন যা আপনি প্রকল্পটি ব্যবহার করতে চান। উদাহরণস্বরূপ:
          {
            ...
            "oauthScopes": [
              "https://www.googleapis.com/auth/spreadsheets.readonly",
              "https://www.googleapis.com/auth/userinfo.email"
            ],
           ...
          }
  8. At the top, click Save .

গ্রানুলার OAuth অনুমতিগুলি পরিচালনা করুন

The granular OAuth consent screen first launched to the Apps Script IDE for users executing a script directly. The consent screen is progressively released to other surfaces, such as macros, triggers, and add-ons, over time. For more information, see Granular OAuth consent in Google Apps Script IDE executions .

The granular OAuth consent screen lets users specify which individual OAuth scopes to authorize. This gives users fine-grained control over what account data they share with each script. For example, if a script requests email and calendar scopes, users can choose to grant Calendar permission but not Gmail.

নিম্নলিখিত বিভাগগুলিতে বর্ণনা করা হয়েছে কিভাবে গ্রানুলার OAuth অনুমতিগুলি পরিচালনা করতে হয়।

প্রয়োজনীয় স্কোপের জন্য স্বয়ংক্রিয়ভাবে অনুমতি প্রয়োজন

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

ScriptApp ক্লাসের নিম্নলিখিত পদ্ধতিগুলি অনুমতি যাচাই করে এবং অনুমোদন প্রম্পট রেন্ডার করে:

  • requireScopes(authMode, oAuthScopes) : নির্দিষ্ট স্কোপের উপর নির্ভরশীল প্রবাহের জন্য এই পদ্ধতিটি ব্যবহার করুন।
  • requireAllScopes(authMode) : যদি কোনও এক্সিকিউশন ফ্লো সমস্ত প্রকল্পের স্কোপের উপর নির্ভর করে তবে এই পদ্ধতিটি ব্যবহার করুন।

উদাহরণ

The following example shows how to call requireScopes() and requireAllScopes() . The script uses scopes for Gmail, Sheets, and Calendar. The sendEmail() function requires only the scopes for Gmail and Sheets while the createEventSendEmail() function requires all scopes used by the script.

// This function requires the Gmail and Sheets scopes.
function sendEmail() {
  // Validates that the user has granted permission for the Gmail and Sheets scopes.
  // If not, the execution ends and prompts the user for authorization.
  ScriptApp.requireScopes(ScriptApp.AuthMode.FULL, [
    'https://mail.google.com/',
    'https://www.googleapis.com/auth/spreadsheets'
  ]);

  // Sends an email.
  GmailApp.sendEmail("dana@example.com", "Subject", "Body");
  Logger.log("Email sent successfully!");

  // Opens a spreadsheet and sheet to track the sent email.
  const ss = SpreadsheetApp.openById("abc1234567");
  const sheet = ss.getSheetByName("Email Tracker")

  // Gets the last row of the sheet.
  const lastRow = sheet.getLastRow();

  // Adds "Sent" to column E of the last row of the spreadsheet.
  sheet.getRange(lastRow, 5).setValue("Sent");
  Logger.log("Sheet updated successfully!");
}

// This function requires all scopes used by the script (Gmail,
// Calendar, and Sheets).
function createEventSendEmail() {
  // Validates that the user has granted permission for all scopes used by the
  // script. If not, the execution ends and prompts the user for authorization.
  ScriptApp.requireAllScopes(ScriptApp.AuthMode.FULL);

  // Creates an event.
  CalendarApp.getDefaultCalendar().createEvent(
    "Meeting",
    new Date("November 28, 2024 10:00:00"),
    new Date("November 28, 2024 11:00:00")
  );
  Logger.log("Calendar event created successfully!");

  // Sends an email.
  GmailApp.sendEmail("dana@example.com", "Subject 2", "Body 2");
  Logger.log("Email sent successfully!");

  // Opens a spreadsheet and sheet to track the created meeting and sent email.
  const ss = SpreadsheetApp.openById("abc1234567");
  const sheet = ss.getSheetByName("Email and Meeting Tracker")
  // Gets the last row
  const lastRow = sheet.getLastRow();

  // Adds "Sent" to column E of the last row
  sheet.getRange(lastRow, 5).setValue("Sent");
  // Adds "Meeting created" to column F of the last row
  sheet.getRange(lastRow, 6).setValue("Meeting created");
  Logger.log("Sheet updated successfully!");
}

অনুপস্থিত স্কোপের জন্য একটি কাস্টম অভিজ্ঞতা তৈরি করুন

You can retrieve the permission status of users and design custom experiences. For example, you might disable features that require missing permissions or display a dialog explaining the requirement. The following methods retrieve an object with the user's permission information that includes which scopes the user has authorized and a URL to request any missing scopes:

  • getAuthorizationInfo(authMode, oAuthScopes) : নির্দিষ্ট স্কোপের জন্য অনুমতির স্থিতি পরীক্ষা করে।
  • getAuthorizationInfo(authMode) : সমস্ত প্রকল্পের স্কোপের জন্য অনুমতির স্থিতি পরীক্ষা করে।

To get the permission details from the authorization info object, such as the list of authorized scopes and the URL to request missing permissions, use the methods from the AuthorizationInfo class .

উদাহরণ

The following example shows how to use getAuthorizationInfo() to skip features where users haven't granted the required scopes. This allows the rest of the execution flow to continue without prompting for authorization of the missing scopes.

// This function uses the Gmail scope and skips the email
// capabilities if the scope for Gmail hasn't been granted.
function myFunction() {
  const authInfo = ScriptApp.getAuthorizationInfo(ScriptApp.AuthMode.FULL, ['https://mail.google.com/']);
  if (authInfo.getAuthorizationStatus() === ScriptApp.AuthorizationStatus.NOT_REQUIRED) {
    GmailApp.sendEmail("dana@example.com", "Subject", "Body");
    Logger.log("Email sent successfully!");
  } else {
    const scopesGranted = ScriptApp.getAuthorizationInfo(ScriptApp.AuthMode.FULL).getAuthorizedScopes();
    console.warn(`Authorized scopes: ${scopesGranted} not enough to send mail, skipping.`);
  }
  // Continue the rest of the execution flow...
}

নিশ্চিত করুন যে ট্রিগার এক্সিকিউশনের অনুমতি আছে

Functions associated with triggers run automatically, and users might not be present to provide permissions. We recommend that you use requireScopes(authMode, oAuthScopes) before installing a trigger. This prompts the user for missing permissions and doesn't allow the installation of the trigger without them.

উদাহরণ

// This function requires scope Sheets.
function trackFormSubmissions(e){
  // Opens a spreadsheet to track the sent email.
  const ss = SpreadsheetApp.openById("abc1234567");
  const sheet = ss.getSheetByName("Submission Tracker")

  // Gets the last row of the sheet.
  const lastRow = sheet.getLastRow();

  // Adds email address of user that submitted the form
  // to column E of the last row of the spreadsheet.
  sheet.getRange(lastRow, 5).setValue(e.name);
  Logger.log("Sheet updated successfully!");
}

function installTrigger(){
  // Validates that the user has granted permissions for trigger
  // installation and execution. If not, trigger doesn't get
  // installed and prompts the user for authorization.
  ScriptApp.requireScopes(ScriptApp.AuthMode.FULL, [
    'https://www.googleapis.com/auth/script.scriptapp',
    'https://www.googleapis.com/auth/spreadsheets',
    'https://www.googleapis.com/auth/forms.currentonly'
  ]);
  ScriptApp.newTrigger('trackFormSubmission')
    .forForm(FormApp.getActiveForm())
    .onFormSubmit()
    .create();
}

OAuth যাচাইকরণ

Certain OAuth scopes are sensitive because they allow access to Google User Data. If your script project uses scopes that allow access to user data, the project must go through OAuth client verification before you can publish it publicly as a web app or add-on . For more information, see the following guides:

সীমাবদ্ধ সুযোগ

In addition to sensitive scopes, certain scopes are classified as restricted and subject to additional rules that help protect user data. If you publish an app that uses restricted scopes, it must comply with all specifications.

প্রকাশের আগে সীমাবদ্ধ স্কোপের সম্পূর্ণ তালিকা পর্যালোচনা করুন। সঙ্গতিপূর্ণ অ্যাপগুলিকে নির্দিষ্ট API স্কোপের জন্য অতিরিক্ত প্রয়োজনীয়তাগুলি অনুসরণ করতে হবে।

পর্যালোচনা প্রক্রিয়া সহজ করার জন্য সম্ভব হলে সীমাবদ্ধ স্কোপ ব্যবহার করা এড়িয়ে চলুন। আপনি অ-সর্বজনীন অ্যাপের জন্য অবাধে সীমাবদ্ধ স্কোপ ব্যবহার করতে পারেন।