Cần có uỷ quyền
Liệt kê các thuộc tính mà người dùng có quyền truy cập. Thử ngay hoặc xem ví dụ.
Ngoài các thông số chuẩn, phương thức này còn hỗ trợ các thông số được liệt kê trong bảng thông số.
Yêu cầu
Yêu cầu HTTP
GET https://www.googleapis.com/analytics/v3/management/accounts/accountId/webproperties
Tham số
Tên thông số | Giá trị | Nội dung mô tả |
---|---|---|
Tham số đường dẫn | ||
accountId |
string |
Mã tài khoản để truy xuất tài sản web. Có thể là một mã tài khoản cụ thể hoặc "~all ", tức là tất cả những tài khoản mà người dùng có quyền truy cập.
|
Tham số truy vấn không bắt buộc | ||
max-results |
integer |
Số lượng thuộc tính web tối đa cần đưa vào phản hồi này. |
start-index |
integer |
Chỉ mục của thực thể đầu tiên cần truy xuất. Dùng tham số này làm cơ chế phân trang cùng với tham số max-results .
|
Ủy quyền
Yêu cầu này cần được uỷ quyền với ít nhất một trong các phạm vi sau (đọc thêm về quy trình xác thực và uỷ quyền).
Phạm vi |
---|
https://www.googleapis.com/auth/analytics |
https://www.googleapis.com/auth/analytics.edit |
https://www.googleapis.com/auth/analytics.readonly |
Nội dung yêu cầu
Không cung cấp nội dung yêu cầu bằng phương thức này.
Phản hồi
Phản hồi này chứa một tài nguyên Thuộc tính web cho mỗi tài sản web Analytics được yêu cầu.
{ "kind": "analytics#webproperties", "username": string, "totalResults": integer, "startIndex": integer, "itemsPerPage": integer, "previousLink": string, "nextLink": string, "items": [ management.webproperties Resource ] }
Tên tài sản | Giá trị | Nội dung mô tả | Ghi chú |
---|---|---|---|
kind |
string |
Loại bộ sưu tập. Giá trị là "analytics#webProperties ". |
|
username |
string |
Mã email của người dùng đã xác thực | |
totalResults |
integer |
Tổng số kết quả cho truy vấn, bất kể số lượng kết quả trong phản hồi. | |
startIndex |
integer |
Chỉ mục bắt đầu của tài nguyên, giá trị này là 1 theo mặc định hoặc được chỉ định bởi tham số truy vấn start-index . |
|
itemsPerPage |
integer |
Số lượng tài nguyên tối đa mà phản hồi có thể chứa, bất kể số lượng tài nguyên thực tế được trả về. Giá trị của biến này nằm trong khoảng từ 1 đến 1000 với giá trị là 1000 theo mặc định hoặc được chỉ định bởi tham số truy vấn
max-results . |
|
previousLink |
string |
Liên kết đến trang trước của bộ sưu tập thuộc tính web này. | |
nextLink |
string |
Liên kết đến trang tiếp theo dành cho bộ sưu tập thuộc tính web này. | |
items[] |
list |
Danh sách các thuộc tính web. |
Ví dụ
Lưu ý: Các đoạn mã mẫu của phương thức này không phải là ví dụ cho mọi ngôn ngữ lập trình được hỗ trợ (xem trang thông tin về các thư viện dùng cho ứng dụng để biết danh sách các ngôn ngữ được hỗ trợ).
Java
Sử dụng thư viện ứng dụng Java.
/** * Note: This code assumes you have an authorized Analytics service object. * See the Web Property Developer Guide for details. */ /** * Example #1: * Requests a list of all properties for the authorized user. */ try { Webproperties properties = analytics.management. webproperties.list("12345").execute(); } catch (GoogleJsonResponseException e) { System.err.println("There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); } /** * Example #2: * Retrieves all properties for the user's account, using a * wildcard '~all' as the accountId. */ Webproperties properties = analytics.management. webproperties.list("~all").execute(); /** * Example #3: * The results of the list method are stored in the properties object. * The following code shows how to iterate through them. */ for (Webproperty property : properties.getItems()) { System.out.println("Account ID: " + property.getAccountId()); System.out.println("Property ID: " + property.getId()); System.out.println("Property Name: " + property.getName()); System.out.println("Property Profile Count: " + property.getProfileCount()); System.out.println("Property Industry Vertical: " + property.getIndustryVertical()); System.out.println("Property Internal Id: " + property.getInternalWebPropertyId()); System.out.println("Property Level: " + property.getLevel(); if (property.getWebsiteUrl() != null) { System.out.println("Property URL: " + property.getWebsiteUrl()); } System.out.println("Property Created: " + property.getCreated()); System.out.println("Property Updated: " + property.getUpdated()); }
1.199
Sử dụng thư viện ứng dụng PHP.
/** * Note: This code assumes you have an authorized Analytics service object. * See the Web Property Developer Guide for details. */ /** * Example #1: * Requests a list of all properties for the authorized user. */ try { $properties = $analytics->management_webproperties ->listManagementWebproperties('123456'); } 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: * Retrieves all properties for the user's account, using a * wildcard ~all as the accountId. */ $properties = $analytics->management_webproperties ->listManagementWebproperties('~all'); /** * Example #3: * The results of the list method are stored in the properties object. * The following code shows how to iterate through them. */ foreach ($properties->getItems() as $property) { $html = <<<HTML <pre> Account id = {$property->getAccountId()} Property id = {$property->getId()} Property name = {$property->getName()} Property URL = {$property->getWebsiteUrl()} Created = {$property->getCreated()} Updated = {$property->getUpdated()} </pre> HTML; print $html; }
Python
Sử dụng thư viện ứng dụng Python.
# Note: This code assumes you have an authorized Analytics service object. # See the Web Property Developer Guide for details. # Example #1: # Requests a list of all properties for the authorized user. try: properties = analytics.management().webproperties().list( accountId='12345').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: # Retrieves all properties for the user's account, using a # wildcard ~all as the accountId. properties = service.management().webproperties().list( accountId='~all').execute() # Example #3: # The results of the list method are stored in the webproperties object. # The following code shows how to iterate through them. for property in properties.get('items', []): print 'Account ID = %s' % property.get('accountId') print 'Property ID = %s' % property.get('id') print 'Property Name = %s' % property.get('name') print 'Property Profile Count = %s' % property.get('profileCount') print 'Property Industry Vertical = %s' % property.get('industryVertical') print 'Property Internal Id = %s' % property.get( 'internalWebPropertyId') print 'Property Level = %s' % property.get('level') if property.get('websiteUrl'): print 'Property URL = %s' % property.get('websiteUrl') print 'Created = %s' % property.get('created') print 'Updated = %s' % property.get('updated')
JavaScript
Sử dụng thư viện ứng dụng JavaScript.
/* * Note: This code assumes you have an authorized Analytics client object. * See the Web Property Developer Guide for details. */ /* * Example 1: * Requests a list of all properties for the authorized user. */ function listProperties() { var request = gapi.client.analytics.management.webproperties.list({ 'accountId': '123456' }); request.execute(printProperties); } /* * Example 2: * The results of the list method are passed as the results object. * The following code shows how to iterate through them. */ function printProperties(results) { if (results && !results.error) { var properties = results.items; for (var i = 0, property; property = properties[i]; i++) { console.log('Account Id: ' + property.accountId); console.log('Property Id: ' + property.id); console.log('Property Name: ' + property.name); console.log('Property Profile Count: ' + property.profileCount); console.log('Property Industry Vertical: ' + property.industryVertical); console.log('Property Internal Id: ' + property.internalWebPropertyId); console.log('Property Level: ' + property.level); if (property.websiteUrl) { console.log('Property URL: ' + property.websiteUrl); } console.log('Created: ' + property.created); console.log('Updated: ' + property.updated); } } }
Hãy dùng thử!
Sử dụng APIs Explorer bên dưới để gọi phương thức này trên dữ liệu trực tiếp và xem phản hồi. Ngoài ra, hãy dùng thử Trình khám phá độc lập.