Class GroupsApp
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
App Gruppi
Questo corso fornisce l'accesso alle informazioni di Google Gruppi. Può essere utilizzato per eseguire query su informazioni come l'indirizzo email di un gruppo o l'elenco dei gruppi di cui l'utente è membro diretto.
Ecco un esempio che mostra quanti gruppi fanno parte dell'utente corrente:
const groups = GroupsApp.getGroups();
Logger.log(`You belong to ${groups.length} groups.`);
Proprietà
Proprietà | Tipo | Descrizione |
Role | Role | |
Documentazione dettagliata
getGroupByEmail(email)
Recupera il gruppo con l'indirizzo email specificato. Viene lanciata un'eccezione se il gruppo non esiste o se non disponi dell'autorizzazione per visualizzarlo.
Di seguito è riportato un esempio che recupera un gruppo tramite il relativo indirizzo email e indica se l'utente corrente è un membro. Prima di eseguire il report, sostituisci l'indirizzo email di esempio con l'indirizzo email di un gruppo reale.
const group = GroupsApp.getGroupByEmail('example@googlegroups.com');
const currentUser = Session.getActiveUser();
if (group.hasUser(currentUser)) {
Logger.log('You are a member of this group.');
} else {
Logger.log('You are not a member of this group.');
}
Parametri
Nome | Tipo | Descrizione |
email | String | L'indirizzo email del gruppo da recuperare. |
Invio
Group
: il gruppo con l'indirizzo email specificato.
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/groups
getGroups()
Recupera tutti i gruppi di cui sei membro diretto (o membro in attesa). Si tratta di un elenco vuoto se non fai parte di nessun gruppo. Viene lanciata un'eccezione se il gruppo non esiste o se non disponi dell'autorizzazione per visualizzarlo.
Ecco un esempio di come stampare l'indirizzo email di ogni gruppo a cui appartiene l'utente:
function showMyGroups() {
const groups = GroupsApp.getGroups();
let str = `You are in ${groups.length} groups: `;
for (let i = 0; i < groups.length; i++) {
const group = groups[i];
str = `${str + group.getEmail()} `;
}
Logger.log(str);
}
Tieni presente che se fai parte di un gruppo B, che è a sua volta membro di un altro gruppo A, hai
indirettamente effettuato l'iscrizione al gruppo A. Anche se ricevi copie dei messaggi inviati al gruppo "principale" A, non hai effettivamente effettuato l'iscrizione a quel gruppo.
Puoi utilizzare Group.getRole(email)
per determinare se sei un membro esistente o in attesa dei gruppi restituiti.
Invio
Group[]
: l'elenco dei gruppi di cui l'utente è membro diretto.
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/groups
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-07-26 UTC.
[null,null,["Ultimo aggiornamento 2025-07-26 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eGroupsApp\u003c/code\u003e class in Apps Script allows you to access and manage Google Groups information, such as retrieving group details and membership status.\u003c/p\u003e\n"],["\u003cp\u003eYou can use \u003ccode\u003egetGroupByEmail()\u003c/code\u003e to retrieve a specific group by its email address and check if the current user is a member.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003egetGroups()\u003c/code\u003e retrieves all groups where the user is a direct or pending member, enabling actions like listing group email addresses.\u003c/p\u003e\n"],["\u003cp\u003eBoth methods require authorization with the \u003ccode\u003ehttps://www.googleapis.com/auth/groups\u003c/code\u003e scope for accessing Google Groups data.\u003c/p\u003e\n"]]],[],null,["# Class GroupsApp\n\nGroupsApp\n\nThis class provides access to Google Groups information. It can be used to query information such\nas a group's email address, or the list of groups in which the user is a direct member.\n\nHere's an example that shows how many groups the current user is a member of:\n\n```javascript\nconst groups = GroupsApp.getGroups();\nLogger.log(`You belong to ${groups.length} groups.`);\n``` \n\n### Properties\n\n| Property | Type | Description |\n|----------|--------------------------------------------|-------------|\n| `Role` | [Role](/apps-script/reference/groups/role) | |\n\n### Methods\n\n| Method | Return type | Brief description |\n|----------------------------------------------------|------------------------------------------------|----------------------------------------------------------------------------------|\n| [getGroupByEmail(email)](#getGroupByEmail(String)) | [Group](/apps-script/reference/groups/group) | Retrieves the group having the specified email address. |\n| [getGroups()](#getGroups()) | [Group[]](/apps-script/reference/groups/group) | Retrieves all the groups of which you are a direct member (or a pending member). |\n\nDetailed documentation\n----------------------\n\n### `get``Group``By``Email(email)`\n\nRetrieves the group having the specified email address. Throws an exception if the group does\nnot exist or if you do not have permission to see it.\n\nHere is an example that gets a group by its email address and outputs whether the current\nuser is a member. Before running, replace the sample email address with a real group's email.\n\n```javascript\nconst group = GroupsApp.getGroupByEmail('example@googlegroups.com');\nconst currentUser = Session.getActiveUser();\nif (group.hasUser(currentUser)) {\n Logger.log('You are a member of this group.');\n} else {\n Logger.log('You are not a member of this group.');\n}\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|---------|----------|---------------------------------------------|\n| `email` | `String` | The email address of the group to retrieve. |\n\n#### Return\n\n\n[Group](/apps-script/reference/groups/group) --- The group with the specified email address.\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/groups`\n\n*** ** * ** ***\n\n### `get``Groups()`\n\nRetrieves all the groups of which you are a direct member (or a pending member). This is an\nempty list if you are not in any groups. Throws an exception if the group does not exist or if\nyou do not have permission to see it.\n\nHere's an example of how to print the email address for every group the user belongs to:\n\n```javascript\nfunction showMyGroups() {\n const groups = GroupsApp.getGroups();\n let str = `You are in ${groups.length} groups: `;\n for (let i = 0; i \u003c groups.length; i++) {\n const group = groups[i];\n str = `${str + group.getEmail()} `;\n }\n Logger.log(str);\n}\n```\nNote that if you are a member of a group, B, which is itself a member of another group, A, then you are *indirectly* subscribed to group A. Even though you receive copies of messages sent to the \"parent\" group A, you are not actually subscribed to that group.\n\nYou can use [Group.getRole(email)](/apps-script/reference/groups/group#getRole(String)) to determine if you are an existing or pending\nmember of the returned groups.\n\n#### Return\n\n\n[Group[]](/apps-script/reference/groups/group) --- The list of groups of which the user is a direct member.\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/groups`"]]