需要授權
列出特定網站資源的 webProperty-Google Ads 連結。 立即試用或參閱範例。
要求
HTTP 要求
GET https://www.googleapis.com/analytics/v3/management/accounts/accountId/webproperties/webPropertyId/entityAdWordsLinks
參數
參數名稱 | 值 | 說明 |
---|---|---|
路徑參數 | ||
accountId |
string |
指定網站資源所屬的帳戶 ID。 |
webPropertyId |
string |
用來擷取 Google Ads 連結的網站資源 ID。 |
選用查詢參數 | ||
max-results |
integer |
此回應內含的 webProperty-Google Ads 連結數量上限。 |
start-index |
integer |
要擷取的第一個 webProperty-Google Ads 連結的索引。請將這個參數當做分頁機制,並搭配 max-results 參數。 |
授權
這項要求需要至少下列其中一個範圍的授權 (進一步瞭解驗證和授權)。
範圍 |
---|
https://www.googleapis.com/auth/analytics.edit |
https://www.googleapis.com/auth/analytics.readonly |
要求主體
請勿使用這個方法提供要求主體。
回應
如果成功的話,這個方法會傳回回應內文,其結構如下:
{ "kind": "analytics#entityAdWordsLinks", "totalResults": integer, "startIndex": integer, "itemsPerPage": integer, "previousLink": string, "nextLink": string, "items": [ management.webPropertyAdWordsLinks Resource ] }
屬性名稱 | 值 | 說明 | 附註 |
---|---|---|---|
kind |
string |
集合類型。 | |
totalResults |
integer |
查詢結果的總數,無論回應中的結果數量為何。 | |
startIndex |
integer |
項目的起始索引,預設為 1,或由 start-index 查詢參數指定。 | |
itemsPerPage |
integer |
回應可包含的項目數量上限,無論傳回的項目數量為何。這個函式的值範圍從 1 到 1000,且預設值為 1000,或者是由 max-results 查詢參數指定。 | |
previousLink |
string |
這個 Google Ads 連結集合的上一個連結。 | |
nextLink |
string |
這個 Google Ads 連結集合的下一個連結。 | |
items[] |
list |
實體 Google Ads 連結清單。 |
示例
注意:這個方法適用的程式語言眾多,我們只在此提供部分程式碼範例,完整的支援語言清單請參閱用戶端程式庫頁面。
Java
使用 Java 用戶端程式庫。
/* * Note: This code assumes you have an authorized Analytics service object. * See the Google Ads Links Developer Guide for details. */ /* * Example #1: * Requests a list of all Google Ads links for the authorized user. */ try { EntityAdWordsLinks adWordsLinks = analytics.management(). webPropertyAdWordsLinks().list("123456", "UA-123456-1").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 adWordsLinks object. * The following code shows how to iterate through them. */ for (EntityAdWordsLink link : adWordsLinks.getItems()) { System.out.println("Link Id = " + link.getId()); System.out.println("Link Kind = " + link.getKind()); System.out.println("Link Name = " + link.getName()); // Get the web property reference from the entity. WebPropertyRef property = link.getEntity().getWebPropertyRef(); System.out.println("Property Id = " + property.getId()); System.out.println("Property Kind = " + property.getKind()); System.out.println("Property Name = " + property.getName()); System.out.println("Property Account Id = " + property.getAccountId()); // Get the Google Ads accounts. List<AdWordsAccount> adWordsAccounts = link.getAdWordsAccounts(); for (AdWordsAccount account : adWordsAccounts) { System.out.println("Account Kind = " + account.getKind()); System.out.println("Account Id = " + account.getCustomerId()); System.out.println("Auto Tagging Enabled = " + account.getAutoTaggingEnabled()); } }
PHP
使用 PHP 用戶端程式庫。
/** * Note: This code assumes you have an authorized Analytics service object. * See the Google Ads Links Developer Guide for details. */ /** * Example #1: * Requests a list of all Google Ads links for the authorized user. */ try { $adWordsLinks = $analytics->management_webPropertyAdWordsLinks ->listManagementwebPropertyAdWordsLinks('123456', 'UA-123456-1'); } 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 adWordsLinks object. * The following code shows how to iterate through them. */ foreach ($adWordsLinks->getItems() as $link) { $html = <<<HTML <pre> Link Id = {$link->getId()} Link Kind = {$link->getKind()} Link Name = {$link->getName()} HTML; // Get the web property reference from the entity. $property = $link->getEntity()->getWebPropertyRef(); $html = <<<HTML Property Id = {$property->getId()} Property Kind = {$property->getKind()} Property Name = {$property->getName()} Property Account Id = {$property->getAccountId()} HTML; // Get the Google Ads accounts. foreach ($link->getAdWordsAccounts as $account) { $html = <<<HTML Account Kind = {$account->getKind()} Account Id = {$account->getCustomerId()} Auto Tagging Enabled = {$account->getAutoTaggingEnabled()} HTML; } $html .= '</pre>'; print $html; }
Python
使用 Python 用戶端程式庫。
# Note: This code assumes you have an authorized Analytics service object. # See the Google Ads Links Developer Guide for details. # Example #1: # Requests a list of all Google Ads links for the authorized user. try: adWordsLinks = analytics.management().webPropertyAdWordsLinks().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)) # Example #2: # The results of the list method are stored in the adWordsLinks object. # The following code shows how to iterate through them. for link in adWordsLinks.get('items', []): print 'Link Id = %s' % link.get('id') print 'Link Kind = %s' % link.get('kind') print 'Link Name = %s' % link.get('name') # Get the property reference from the entity. property = link.get('entity', {}).get('webPropertyRef', {}) print 'Property Id = %s' % property.get('id') print 'Property Kind = %s' % property.get('kind') print 'Property Name = %s' % property.get('name') print 'Property Account id = %s' % property.get('accountId') # Get the Google Ads accounts. adWordsAccounts = link.get('adWordsAccounts', []) for account in adWordsAccounts: print 'Account Id = %s' % account.get('id') print 'Account Kind = %s' % account.get('kind') print 'Auto Tagging Enabled = %s' % account.get('autoTaggingEnabled')
JavaScript
/* * Note: This code assumes you have an authorized Analytics client object. * See the Google Ads Links Developer Guide for details. */ /* * Example 1: * Requests a list of all Google Ads links for the authorized user. */ function listAdWordsLinks() { var request = gapi.client.analytics.management.webPropertyAdWordsLinks.list({ 'accountId': '123456', 'webPropertyId': 'UA-123456-1' }); request.execute(printViews); } /* * Example 2: * The results of the list method are passed as the results object. * The following code shows how to iterate through them. */ function printViews(results) { if (results && !results.error) { var adWordsLinks = results.items; for (var i = 0, link; link = adWordsLinks[i]; i++) { console.log('Link Id: ' + link.id); console.log('Link Kind: ' + link.kind); console.log('Link Name: ' + link.name); // Get the property reference from the entity. var property = link.entity.webPropertyRef; console.log('Property Id: ' + property.id); console.log('Property Kind: ' + property.kind); console.log('Property Name: ' + property.name); console.log('Property Account id: ' + property.accountId); // Get the Google Ads accounts. var adWordsAccounts = link.adWordsAccounts; for (var j = 0, account; account = adWordsAccounts[j]; j++) { console.log('Account Id: ' + account.customerId); console.log('Account Kind: ' + account.kind); console.log('Auto Tagging Enabled: ' + account.autoTaggingEnabled); } } } }
試試看!
使用下方的 APIs Explorer,針對有效資料呼叫這個方法,然後查看回應。 或者,您也可以試試獨立的 Explorer。