נדרשת הרשאה
בתיבת הדו-שיח הזו מפורטים כל פקודות המאקרו של GTM. אפשר לנסות עכשיו או לראות דוגמה.
בקשה
בקשת HTTP
GET https://www.googleapis.com/tagmanager/v1/accounts/accountId/containers/containerId/macros
פרמטרים
שם הפרמטר | Value | התיאור |
---|---|---|
פרמטרים של נתיב | ||
accountId |
string |
מספר החשבון ב-GTM. |
containerId |
string |
מזהה מאגר התגים של GTM. |
הרשאות
בקשה זו מחייבת הרשאה עם לפחות אחד מההיקפים הבאים (למידע נוסף על אימות והרשאה).
היקף |
---|
https://www.googleapis.com/auth/tagmanager.readonly |
https://www.googleapis.com/auth/tagmanager.edit.containers |
גוף הבקשה
אל תספקו גוף הבקשה בשיטה הזו.
תשובה
אם הפעולה בוצעה ללא שגיאות, השיטה הזו מחזירה גוף תגובה במבנה הבא:
{ "macros": [ accounts.containers.macros Resource ] }
שם הנכס | Value | התיאור | הערות |
---|---|---|---|
macros[] |
list |
כל פקודות המאקרו של GTM במאגר של GTM. |
דוגמאות
הערה: דוגמאות הקוד הזמינות לשיטה זו לא מייצגות את כל שפות התכנות הנתמכות (רשימת השפות הנתמכות זמינה בדף של ספריות המשתמשים).
Java
משתמש בספריית הלקוח של Java.
/* * Note: This code assumes you have an authorized tagmanager service object. */ /* * This requests lists all macros for the authorized user. */ try { ListMacrosResponse macros = tagmanager.accounts().containers(). macros().list("123456", "54321").execute(); } catch (GoogleJsonResponseException e) { System.err.println("There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); } /* * The results of the list method are stored in the macros object. * The following code shows how to iterate through them. */ for (Macro macro : macros.getMacros()) { System.out.println("Account Id = " + macro.getAccountId()); System.out.println("Container Id = " + macro.getContainerId()); System.out.println("Macro Id = " + macro.getMacroId()); System.out.println("Macro Name = " + macro.getName()); System.out.println("Macro Type = " + macro.getType()); System.out.println("Macro Notes = " + macro.getNotes()); if (macro.getParameter() != null) { for (Parameter parameter : macro.getParameter()) { System.out.println("Parameter Type = " + parameter.getType()); System.out.println("Parameter Key = " + parameter.getKey()); System.out.println("Parameter Value = " + parameter.getValue()); } } if (macro.getEnablingRuleId() != null) { for (String enabllingRuleId : macro.getEnablingRuleId()) { System.out.println("Macro Enabling Rule Id = " + enabllingRuleId); } } if (macro.getDisablingRuleId() != null) { for (String disablingRuleId : macro.getDisablingRuleId()) { System.out.println("Macro Disabling Rule Id " + disablingRuleId); } } System.out.println("Macro Fingerprint = " + macro.getFingerprint()); }
Python
עושה שימוש בספריית הלקוח של Python.
# Note: This code assumes you have an authorized tagmanager service object. # This request lists all macros for the authorized user. try: macros = tagmanager.accounts().containers().macros().list( accountId='123456', containerId='54321' ).execute() except TypeError, error: # Handle errors in constructing a query. print 'There was an error in constructing your query : %s' % error except HttpError, error: # Handle API errors. print ('There was an API error : %s : %s' % (error.resp.status, error.resp.reason)) # The results of the list method are stored in the macros object. # The following code shows how to iterate through them. for macro in macros.get('macros', []): print 'Account Id = %s' % macro.get('accountId') print 'Container Id = %s' % macro.get('containerId') print 'Macro Id = %s' % macro.get('macroId') print 'Macro Name = %s' % macro.get('name') print 'Macro Type = %s' % macro.get('type') print 'Macro notes = %s' % macro.get('notes') print 'Schedule Start ms = %s' % macro.get('scheduleStartMs') print 'Schedule End ms = %s' % macro.get('scheduleEndMs') for parameter in macro.get('parameter', []): print 'Parameter Type = %s' % parameter.get('type') print 'Parameter Key = %s' % parameter.get('key') print 'Parameter Value = %s' % parameter.get('value') for enablingRuleId in macro.get('enablingRuleId', []): print 'Macro Enabling Rule Id = %s' % enablingRuleId for disablingRuleId in macro.get('disablingRuleId', []): print 'Macro Disabling Rule Id = %s' % disablingRuleId print 'Macro Fingerprint = %s\n\n' % macro.get('fingerprint')
רוצה לנסות?
ניתן להשתמש ב-APIs Explorer שבהמשך כדי לקרוא לשיטה הזו בנתונים בזמן אמת ולראות את התגובה.