نیاز به مجوز دارد
معیارهای سفارشی را که کاربر به آنها دسترسی دارد فهرست می کند. اکنون آن را امتحان کنید یا نمونه ای را ببینید .
درخواست
درخواست HTTP
GET https://www.googleapis.com/analytics/v3/management/accounts/accountId/webproperties/webPropertyId/customMetrics
مولفه های
نام پارامتر | ارزش | شرح |
---|---|---|
پارامترهای مسیر | ||
accountId | string | شناسه حساب برای معیارهای سفارشی برای بازیابی. |
webPropertyId | string | شناسه دارایی وب برای معیارهای سفارشی برای بازیابی. |
پارامترهای پرس و جو اختیاری | ||
max-results | integer | حداکثر تعداد معیارهای سفارشی برای درج در این پاسخ. |
start-index | integer | شاخصی از اولین موجودی که بازیابی می شود. از این پارامتر به عنوان مکانیزم صفحه بندی به همراه پارامتر max-results استفاده کنید. |
مجوز
این درخواست به مجوز حداقل با یکی از حوزه های زیر نیاز دارد ( در مورد احراز هویت و مجوز بیشتر بخوانید ).
محدوده |
---|
https://www.googleapis.com/auth/analytics.readonly |
https://www.googleapis.com/auth/analytics |
درخواست بدن
با این روش بدنه درخواستی ارائه نکنید.
واکنش
در صورت موفقیت آمیز بودن، این روش یک بدنه پاسخ با ساختار زیر را برمی گرداند:
{ "kind": "analytics#customMetrics", "username": string, "totalResults": integer, "startIndex": integer, "itemsPerPage": integer, "previousLink": string, "nextLink": string, "items": [ management.customMetrics Resource ] }
نام ملک | ارزش | شرح | یادداشت |
---|---|---|---|
kind | string | نوع مجموعه | |
username | string | شناسه ایمیل کاربر احراز هویت شده | |
totalResults | integer | تعداد کل نتایج برای پرس و جو، صرف نظر از تعداد نتایج در پاسخ. | |
startIndex | integer | شاخص شروع منابع که به طور پیشفرض 1 است یا توسط پارامتر جستجوی start-index مشخص میشود. | |
itemsPerPage | integer | حداکثر تعداد منابعی که پاسخ می تواند داشته باشد، صرف نظر از تعداد واقعی منابع برگشتی. مقدار آن از 1 تا 1000 با مقدار 1000 به طور پیش فرض متغیر است، یا در غیر این صورت توسط پارامتر query max-results مشخص شده است. | |
previousLink | string | پیوند به صفحه قبلی برای این مجموعه متریک سفارشی. | |
nextLink | string | پیوند به صفحه بعدی برای این مجموعه متریک سفارشی. | |
items[] | list | مجموعه معیارهای سفارشی |
مثال ها
توجه: نمونههای کد موجود برای این روش همه زبانهای برنامهنویسی پشتیبانیشده را نشان نمیدهند (برای فهرست زبانهای پشتیبانیشده به صفحه کتابخانههای سرویس گیرنده مراجعه کنید).
جاوا
از کتابخانه سرویس گیرنده جاوا استفاده می کند.
/** * Note: This code assumes you have an authorized Analytics service object. */ /** * This request lists all custom metrics for the authorized user. */ try { CustomMetrics metrics = analytics.management.customMetrics .list("12345", "UA-12345-1").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 metrics object. * The following code shows how to iterate through them. */ for (CustomMetric metric : metrics.getItems()) { System.out.println("Metric Kind: " + metric.getKind()); System.out.println("Metric Id: " + metric.getId()); System.out.println("Account ID: " + metric.getAccountId()); System.out.println("Property ID: " + metric.getWebPropertyId()); System.out.println("Metric Name: " + metric.getName()); System.out.println("Metric Index: " + metric.getIndex()); System.out.println("Metric Scope: " + metric.getScope()); System.out.println("Metric Active: " + metric.getActive()); System.out.println("Metric Type: " + metric.getType()); System.out.println("Metric Created: " + metric.getCreated()); System.out.println("Metric Updated: " + metric.getUpdated()); }
پایتون
از کتابخانه کلاینت پایتون استفاده می کند.
# Note: This code assumes you have an authorized Analytics service object. # This request lists all custom metrics for the authorized user. try: metrics = analytics.management().customMetrics().list( accountId='123456', webPropertyId='UA-123456-1', ).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 metrics object. # The following code shows how to iterate through them. for metric in metrics.get('items', []): print 'Metric Kind = %s' % metric.get('kind') print 'Metric Id = %s' % metric.get('id') print 'Account ID = %s' % metric.get('accountId') print 'Property ID = %s' % metric.get('webPropertyId') print 'Metric Name = %s' % metric.get('name') print 'Metric Index = %s' % metric.get('index') print 'Metric Scope = %s' % metric.get('scope') print 'Metric Active = %s' % metric.get('active') print 'Metric Type = %s' % metric.get('type') print 'Metric Created = %s' % metric.get('created') print 'Metric Updated = %s' % metric.get('updated')
آن را امتحان کنید!
از APIs Explorer زیر برای فراخوانی این روش در دادههای زنده و دیدن پاسخ استفاده کنید. از طرف دیگر، اکسپلورر مستقل را امتحان کنید.