Accounts: list

نیاز به مجوز دارد

تمام حساب هایی را که کاربر به آنها دسترسی دارد فهرست می کند. اکنون آن را امتحان کنید یا نمونه ای را ببینید .

علاوه بر پارامترهای استاندارد ، این روش از پارامترهای فهرست شده در جدول پارامترها پشتیبانی می کند.

درخواست

درخواست HTTP

GET https://www.googleapis.com/analytics/v3/management/accounts

مولفه های

نام پارامتر ارزش شرح
پارامترهای پرس و جو اختیاری
max-results integer حداکثر تعداد حساب‌هایی که باید در این پاسخ لحاظ شود.
start-index integer فهرستی از اولین حسابی که باید بازیابی شود. از این پارامتر به عنوان مکانیزم صفحه بندی به همراه پارامتر max-results استفاده کنید.

مجوز

این درخواست به مجوز حداقل با یکی از حوزه های زیر نیاز دارد ( در مورد احراز هویت و مجوز بیشتر بخوانید ).

محدوده
https://www.googleapis.com/auth/analytics
https://www.googleapis.com/auth/analytics.edit
https://www.googleapis.com/auth/analytics.readonly

درخواست بدن

با این روش بدنه درخواستی ارائه نکنید.

واکنش

در صورت موفقیت آمیز بودن، این روش یک بدنه پاسخ با ساختار زیر را برمی گرداند:

{
  "kind": "analytics#accounts",
  "username": string,
  "totalResults": integer,
  "startIndex": integer,
  "itemsPerPage": integer,
  "previousLink": string,
  "nextLink": string,
  "items": [
    management.accounts Resource
  ]
}
نام ملک ارزش شرح یادداشت
kind string نوع مجموعه مقدار " analytics#accounts " است.
username string شناسه ایمیل کاربر احراز هویت شده
totalResults integer تعداد کل نتایج برای پرس و جو، صرف نظر از تعداد نتایج در پاسخ.
startIndex integer نمایه شروع ورودی ها که به طور پیش فرض 1 است یا توسط پارامتر جستجوی start-index مشخص شده است.
itemsPerPage integer حداکثر تعداد ورودی‌هایی که پاسخ می‌تواند داشته باشد، صرف‌نظر از تعداد واقعی ورودی‌های برگشتی. مقدار آن از 1 تا 1000 با مقدار 1000 به طور پیش فرض متغیر است، یا در غیر این صورت توسط پارامتر query max-results مشخص شده است.
items[] list لیستی از حساب ها

مثال ها

توجه: نمونه‌های کد موجود برای این روش همه زبان‌های برنامه‌نویسی پشتیبانی‌شده را نشان نمی‌دهند (برای فهرست زبان‌های پشتیبانی‌شده به صفحه کتابخانه‌های سرویس گیرنده مراجعه کنید).

جاوا

از کتابخانه سرویس گیرنده جاوا استفاده می کند.

/**
 * Note: This code assumes you have an authorized Analytics service object.
 * See the Account Developer Guide for details.
 */

/**
 * Example #1:
 * Requests a list of all accounts for the authorized user.
 */
try {
  Accounts accounts = analytics.management.accounts.list().execute();

} catch (GoogleJsonResponseException e) {
  System.err.println("There was a service error: "
      + e.getDetails().getCode() + " : "
      + e.getDetails().getMessage());
}


/**
 * Example #2:
 * The results of the list method are stored in the accounts object.
 * The following code shows how to iterate through them.
 */
for (Account account : accounts.getItems()) {
  System.out.println("Account ID: " + account.getId());
  System.out.println("Account Name: " + account.getName());
  System.out.println("Account Created: " + account.getCreated());
  System.out.println("Account Updated: " + account.getUpdated());
}

PHP

از کتابخانه مشتری PHP استفاده می کند.

/**
 * Note: This code assumes you have an authorized Analytics service object.
 * See the Accounts Developer Guide for details.
 */

/**
 * Example #1:
 * Requests a list of all accounts for the authorized user.
 */
try {
  $accounts = $analytics->management_accounts->listManagementAccounts();
} catch (apiServiceException $e) {
  print 'There was an Analytics API service error '
      . $e->getCode() . ':' . $e->getMessage();

} catch (apiException $e) {
  print 'There was a general API error '
      . $e->getCode() . ':' . $e->getMessage();
}

/**
 * Example #2:
 * The results of the list method are stored in the accounts object.
 * The following code shows how to iterate through them.
 */
foreach ($accounts->getItems() as $account) {
  $html = <<<HTML
<pre>
Account id   = {$account->getId()}
Account name = {$account->getName()}
Created      = {$account->getCreated()}
Updated      = {$account->getUpdated()}
</pre>
HTML;
  print $html;
}

پایتون

از کتابخانه کلاینت پایتون استفاده می کند.

# Note: This code assumes you have an authorized Analytics service object.
# See the Account Developer Guide for details.

# Example #1:
# Requests a list of all accounts for the authorized user.
try:
  accounts = analytics.management().accounts().list().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))


# Example #2:
# The results of the list method are stored in the accounts object.
# The following code shows how to iterate through them.
for account in accounts_response.get('items', []):
  print 'Account ID      = %s' % account.get('id')
  print 'Account Name    = %s' % account.get('name')
  print 'Created         = %s' % account.get('created')
  print 'Updated         = %s' % account.get('updated')

جاوا اسکریپت

از کتابخانه سرویس گیرنده جاوا اسکریپت استفاده می کند.

/*
 * Note: This code assumes you have an authorized Analytics client object.
 * See the Account Developer Guide for details.
 */

/*
 * Example 1:
 * Requests a list of all accounts for the authorized user.
 */
function listAccounts() {
  var request = gapi.client.analytics.management.accounts.list();
  request.execute(printAccounts);
}

/*
 * Example 2:
 * The results of the list method are passed as the results object.
 * The following code shows how to iterate through them.
 */
function printAccounts(results) {
  if (results && !results.error) {
    var accounts = results.items;
    for (var i = 0, account; account = accounts[i]; i++) {
      console.log('Account Id: ' + account.id);
      console.log('Account Kind: ' + account.kind);
      console.log('Account Name: ' + account.name);
      console.log('Account Created: ' + account.created);
      console.log('Account Updated: ' + account.updated);
    }
  }
}

آن را امتحان کنید!

از APIs Explorer زیر برای فراخوانی این روش در داده‌های زنده و دیدن پاسخ استفاده کنید. از طرف دیگر، اکسپلورر مستقل را امتحان کنید.