קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
כשמבקשים הרשאת גישה לנתוני משתמשים או למשאבים אחרים, אפשר לבקש את כל היקפי ההרשאות מראש בבקשה הראשונית או בהיקפי הבקשה לפי הצורך, באמצעות הרשאה מצטברת.
כשמשתמשים באישור מצטבר, האפליקציה מבקשת בהתחלה רק את ההיקפים הנדרשים להפעלת האפליקציה, ולאחר מכן מבקשת היקפים נוספים לפי הצורך בהרשאות חדשות, בהקשר שמציין למשתמש את הסיבה לבקשה.
לדוגמה, נניח שהאפליקציה שלכם מאפשרת למשתמשים לשמור פלייליסטים של מוזיקה ב-Google Drive. האפליקציה יכולה לבקש מידע בסיסי על המשתמש בזמן הכניסה, ולאחר מכן, כשהמשתמש יהיה מוכן לשמור את הפלייליסט הראשון שלו, לבקש רק הרשאות ל-Google Drive.
מומלץ להשתמש בשיטה הזו אם אתם חושדים שהמשתמשים לא נכנסים לחשבון כי מסך ההסכמה שלכם עמוס מדי, או שהם לא מבינים למה הם מתבקשים להביע הסכמה להרשאות מסוימות.
ההוראות הבאות מיועדות לאינטרנט, ונובעות מההוראות להוספת לחצן כניסה בצד הלקוח: יצירת לחצן כניסה באמצעות Google 2.0.
מידע נוסף על הרשאה מצטברת לאינטרנט זמין במסמכי העזרה של OAuth 2.0.
בקשה להיקפים נוספים
במהלך הכניסה, האפליקציה מבקשת היקפים "בסיסיים", שכוללים את היקף הכניסה profile וכל היקפי הרשאות ראשוניים אחרים שהאפליקציה מחייבת לצורך הפעלה.
מאוחר יותר, כשהמשתמש ירצה לבצע פעולה שדורשת היקפי גישה נוספים, האפליקציה תבקש את ההיקפים הנוספים האלה והמשתמש יאשר רק את ההיקפים החדשים במסך הסכמה.
שלב 1: מבקשים היקפי גישה בסיסיים
מבקשים את היקף הבסיס profile כשמאתחלים את הכניסה באמצעות חשבון Google. השלב הזה כלול במאמר יצירת לחצן כניסה ל-Google 2.0.
auth2=gapi.auth2.init({client_id:'CLIENT_ID.apps.googleusercontent.com',cookiepolicy:'single_host_origin',/** Default value **/scope:'profile'});/** Base scope **/
שלב 2: מבקשים היקפים נוספים
בכל מקום שבו נדרשים היקפי גישה נוספים, מבקשים אותם על ידי יצירה של בונה אפשרויות עם ההיקפים שרוצים להוסיף, ואז קוראים ל-user.grant({scope:
[OPTIONS BUILDER]}).then(successFunction, failFunction);:
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-07-25 (שעון UTC)."],[[["\u003cp\u003eThe Google Sign-In JavaScript Platform Library is deprecated; developers should migrate to the Google Identity Services library for user authorization and access tokens.\u003c/p\u003e\n"],["\u003cp\u003eFedCM APIs will become mandatory for the Google Sign-In library, requiring developers to conduct an impact assessment.\u003c/p\u003e\n"],["\u003cp\u003eIncremental authorization allows developers to request user permissions in stages, starting with basic scopes and requesting additional scopes as needed, improving user experience.\u003c/p\u003e\n"],["\u003cp\u003eTo implement incremental authorization, request the 'profile' scope initially and add further scopes like 'email' or 'drive' using \u003ccode\u003egapi.auth2.SigninOptionsBuilder\u003c/code\u003e and \u003ccode\u003euser.grant()\u003c/code\u003e when required.\u003c/p\u003e\n"]]],[],null,["# Requesting additional permissions\n\n| **Warning:** The Google Sign-In library optionally uses FedCM APIs, and their use will become a requirement. [Conduct an impact assessment](/identity/sign-in/web/gsi-with-fedcm) to confirm that user sign-in continues to function as expected. \n|\n| Support for the Google Sign-In library is deprecated, see the [Deprecation and Sunset](/identity/sign-in/web/deprecation-and-sunset) guide for more.\n| **Warning:** We are [discontinuing the Google Sign-In JavaScript Platform Library for web](https://developers.googleblog.com/2021/08/gsi-jsweb-deprecation.html). For user authorization and to obtain access tokens for use with Google APIs, use the newer [Google Identity Services JavaScript library](/identity/oauth2/web/guides/overview) instead. For existing implementations see [Migrate to Google Identity Services](/identity/oauth2/web/guides/migration-to-gis).\n\nWhen requesting user permission to access user data or other\nresources, you can request all scopes up-front in the initial request or\nrequest scopes only as needed, using *incremental authorization*.\nUsing incremental authorization, your app initially requests only the scopes\nrequired to start your app, then requests additional scopes as new permissions\nare required, in a context that identifies the reason for the request to the\nuser.\n\nFor example, suppose your app lets users save music playlists\nto Google Drive; your app can request basic user information at sign-in,\nand later, when the user is ready to save their first playlist,\nask only for Google Drive permissions.\n\nUse this technique if you suspect users are not signing in because your\nconsent screen is overwhelming, or are confused about why they are being asked\nfor certain permissions.\nThe following instructions are for the web, and are derived from the\ninstructions for adding a client-side sign-in button:\n[Building a Google 2.0 Sign-In button](/identity/sign-in/web/build-button).\nYou can read more about incremental authorization for the web in the\n[OAuth 2.0 documentation](/identity/protocols/oauth2/web-server#incrementalAuth).\n\nRequesting additional scopes\n----------------------------\n\nAt sign-in, your app requests \"base\" scopes, consisting of the sign-in scope\n`profile` plus any other initial scopes your app requires for operation.\nLater, when the user wants to perform an action that requires additional\nscopes, your app requests those additional scopes and the user authorizes only\nthe new scopes from a consent screen.\n\n### Step 1: Request base scopes\n\nRequest the base scope `profile` when you initialize Google Sign-In. This\nstep is included in\n[Building a Google 2.0 Sign-In button](/identity/sign-in/web/build-button). \n\n auth2 = gapi.auth2.init({\n client_id: 'CLIENT_ID.apps.googleusercontent.com',\n cookiepolicy: 'single_host_origin', /** Default value **/\n scope: 'profile' }); /** Base scope **/\n\n### Step 2: Request additional scopes\n\nWherever additional scopes are needed, request them by constructing an options\nbuilder with the scopes you want to add and then calling `user.grant({scope:\n[OPTIONS BUILDER]}).then(successFunction, failFunction);`: \n\n const options = new gapi.auth2.SigninOptionsBuilder();\n options.setScope('email https://www.googleapis.com/auth/drive');\n\n googleUser = auth2.currentUser.get();\n googleUser.grant(options).then(\n function(success){\n console.log(JSON.stringify({message: \"success\", value: success}));\n },\n function(fail){\n alert(JSON.stringify({message: \"fail\", value: fail}));\n });"]]