Memerlukan otorisasi
Mencantumkan semua akun yang aksesnya dimiliki oleh pengguna. Coba sekarang atau lihat contoh.
Selain parameter standar, metode ini mendukung parameter yang tercantum dalam tabel parameter.
Permintaan
Permintaan HTTP
GET https://www.googleapis.com/analytics/v3/management/accounts
Parameter
Nama parameter | Nilai | Deskripsi |
---|---|---|
Parameter kueri opsional | ||
max-results |
integer |
Jumlah maksimum akun untuk disertakan dalam respons ini. |
start-index |
integer |
Indeks akun pertama yang akan diambil. Gunakan parameter ini sebagai mekanisme penomoran halaman bersama dengan parameter max-results .
|
Otorisasi
Permintaan ini memerlukan otorisasi dengan setidaknya salah satu cakupan berikut (baca selengkapnya tentang autentikasi dan otorisasi).
Cakupan |
---|
https://www.googleapis.com/auth/analytics |
https://www.googleapis.com/auth/analytics.edit |
https://www.googleapis.com/auth/analytics.readonly |
Isi permintaan
Jangan menyediakan isi permintaan dengan metode ini.
Tanggapan
Jika berhasil, metode ini menampilkan isi respons dengan struktur berikut:
{ "kind": "analytics#accounts", "username": string, "totalResults": integer, "startIndex": integer, "itemsPerPage": integer, "previousLink": string, "nextLink": string, "items": [ management.accounts Resource ] }
Nama properti | Nilai | Deskripsi | Catatan |
---|---|---|---|
kind |
string |
Jenis koleksi. Nilai adalah "analytics#accounts ". |
|
username |
string |
ID email pengguna yang diautentikasi | |
totalResults |
integer |
Jumlah total hasil untuk kueri, berapa pun jumlah hasil dalam respons. | |
startIndex |
integer |
Indeks awal entri, yaitu 1 secara default atau ditentukan oleh parameter kueri start-index . |
|
itemsPerPage |
integer |
Jumlah entri maksimum yang dapat ditampung oleh respons, berapa pun jumlah entri sebenarnya yang ditampilkan. Nilainya berkisar dari 1 hingga 1000 dengan nilai 1000 secara default, atau ditentukan oleh parameter kueri max-results . |
|
previousLink |
string |
Link sebelumnya untuk koleksi akun ini. | |
nextLink |
string |
Link berikutnya untuk koleksi akun ini. | |
items[] |
list |
Daftar akun. |
Contoh
Catatan: Contoh kode yang tersedia untuk metode ini tidak merepresentasikan semua bahasa pemrograman yang didukung (lihat halaman library klien untuk mengetahui daftar bahasa yang didukung).
Java
Menggunakan library klien Java.
/** * 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
Menggunakan library klien 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; }
Python
Menggunakan library klien Python.
# 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')
JavaScript
Menggunakan library klien JavaScript.
/* * 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); } } }
Cobalah!
Gunakan APIs Explorer di bawah untuk memanggil metode ini pada data live dan melihat responsnya. Atau, coba Penjelajah mandiri.