0

我们可以在谷歌分析中手动创建属性。但我想通过编写 c# 代码来创建新属性。我不知道我需要使用哪个 API。请帮助我使用 c# 代码创建属性。

4

1 回答 1

0

views.insert方法将允许您插入新的 provile / 视图。

 /// Create a new view (profile). 
        /// Documentation https://developers.google.com/analytics/v3/reference/profiles/insert
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Analytics service.</param>  
        /// <param name="accountId">Account ID to create the view (profile) for.</param>
        /// <param name="webPropertyId">Web property ID to create the view (profile) for.</param>
        /// <param name="body">A valid Analytics v3 body.</param>
        /// <returns>ProfileResponse</returns>
        public static Profile Insert(AnalyticsService service, string accountId, string webPropertyId, Profile body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                    throw new ArgumentNullException("service");
                if (body == null)
                    throw new ArgumentNullException("body");
                if (accountId == null)
                    throw new ArgumentNullException(accountId);
                if (webPropertyId == null)
                    throw new ArgumentNullException(webPropertyId);

                // Make the request.
                return service.Profiles.Insert(body, accountId, webPropertyId).Execute();
            }
            catch (Exception ex)
            {
                throw new Exception("Request Profiles.Insert failed.", ex);
            }
        }

从ProfilesSampleManagement中提取的代码

于 2018-12-05T12:08:22.027 回答