需要授權
要求
HTTP 要求
POST https://www.googleapis.com/analytics/v3/management/accounts/accountId/webproperties/webPropertyId/profiles/profileId/profileFilterLinks
參數
參數名稱 | 值 | 說明 |
---|---|---|
路徑參數 | ||
accountId |
string |
要建立設定檔篩選器連結的帳戶 ID。 |
profileId |
string |
要建立篩選器連結的個人資料 ID。 |
webPropertyId |
string |
要建立設定檔篩選器連結的網站資源 ID。 |
授權
這項要求需要下列範圍的授權 (進一步瞭解驗證和授權)。
範圍 |
---|
https://www.googleapis.com/auth/analytics.edit |
要求主體
在要求內文中,提供設定檔篩選器連結資源並附上以下屬性:
資源名稱 | 值 | 說明 | 附註 |
---|---|---|---|
必要屬性 | |||
filterRef.id |
string |
篩選器 ID。 | 可寫入 |
選用屬性 | |||
rank |
integer |
此設定檔篩選器連結相對於相同設定檔所連結其他篩選器的排名。 如果是唯讀 (例如 list 和 get) 作業,排名一律從 1 開始。 在寫入 (即建立、更新或刪除) 作業方面,您可以指定介於 0 到 255 (含 0, 255) 之間的值。如要在清單結尾插入連結,請勿指定排名或將其排名設為高於清單中最高排名的數字。如要在清單開頭插入連結,請指定小於或等於 1 的排名。新的連結會將所有現有篩選器往下移。插入/更新/刪除連結後,系統會自 1 起重新編號所有設定檔篩選器連結。 |
可寫入 |
回應
如果成功的話,這個方法會在回應內文中傳回設定檔篩選器連結資源。
示例
注意:這個方法適用的程式語言眾多,我們只在此提供部分程式碼範例,完整的支援語言清單請參閱用戶端程式庫頁面。
Java
使用 Java 用戶端程式庫。
/* * Note: This code assumes you have an authorized Analytics service object. * See the Filters Developer Guide for details. */ /* * This request creates a new profile filter link. */ // Construct the filter reference. FilterRef filterRef = new FilterRef(); filterRef.setId("1223334444"); // Construct the body of the request. ProfileFilterLink body = new ProfileFilterLink(); body.setFilterRef(filterRef); try { analytics.management().profileFilterLinks().insert("123456", "UA-123456-1", "7654321", body).execute(); } catch (GoogleJsonResponseException e) { System.err.println("There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); }
Python
使用 Python 用戶端程式庫。
# Note: This code assumes you have an authorized Analytics service object. # See the Filters Developer Guide for details. # This request creates a new profile filter link. try: analytics.management().profileFilterLinks().insert( accountId='123456', webPropertyId='UA-123456-1', profileId='7654321', body={ 'filterRef': { 'id': '1223334444' } } ).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))
試試看!
使用下方的 APIs Explorer,針對有效資料呼叫這個方法,然後查看回應。 或者,您也可以試試獨立的 Explorer。