/// <summary> /// Links the specified AdWords account to the specified merchant center account. /// </summary> /// <returns>The account that was linked.</returns> private AccountAdwordsLink LinkAdWordsAccount(ulong merchantId, ulong adWordsAccountId) { Console.WriteLine("================================================================="); Console.WriteLine(String.Format("Linking AdWords account {0}", adWordsAccountId)); Console.WriteLine("================================================================="); // First, retrieve list of AdWords accounts. Account account = service.Accounts.Get(merchantId, merchantId).Execute(); var newAccountAdWords = new AccountAdwordsLink(); newAccountAdWords.AdwordsId = adWordsAccountId; newAccountAdWords.Status = "active"; if (account.AdwordsLinks == null) { account.AdwordsLinks = new List <AccountAdwordsLink>(); } account.AdwordsLinks.Add(newAccountAdWords); // Set ETag to null as Patch() will reject it otherwise. account.ETag = null; // Patch the new list of links. Account response = service.Accounts.Patch(account, merchantId, merchantId).Execute(); Console.WriteLine("AdWords account \"{0}\" was added to account {1}.", adWordsAccountId, response.Id); Console.WriteLine(); return(newAccountAdWords); }
/// <summary> /// Links the specified AdWords account to the specified merchant center account. /// </summary> /// <returns>The account that was linked.</returns> private AccountAdwordsLink LinkAdWordsAccount(ulong merchantId, ulong adWordsAccountId) { Console.WriteLine("================================================================="); Console.WriteLine(String.Format("Linking AdWords account {0}", adWordsAccountId)); Console.WriteLine("================================================================="); // First, retrieve list of AdWords accounts. Account account = service.Accounts.Get(merchantId, merchantId).Execute(); var newAccountAdWords = new AccountAdwordsLink(); newAccountAdWords.AdwordsId = adWordsAccountId; newAccountAdWords.Status = "active"; if (account.AdwordsLinks == null) { account.AdwordsLinks = new List<AccountAdwordsLink>(); } account.AdwordsLinks.Add(newAccountAdWords); // Set ETag to null as Patch() will reject it otherwise. account.ETag = null; // Patch the new list of links. Account response = service.Accounts.Patch(account, merchantId, merchantId).Execute(); Console.WriteLine("AdWords account \"{0}\" was added to account {1}.", adWordsAccountId, response.Id); Console.WriteLine(); return newAccountAdWords; }