Hi, I am trying to create products in Adwords by using data from my database like that:
spgCampaignId spgCampaign spgAdgroupId spgAdgroup spgProductgroupParent spgProductgroupChild spgCPCBid 1543848623 TEST Shopping 57344990085 Test ad group * / PRODUCT_TYPE_L1 = "heren" / PRODUCT_TYPE_L2 = "werksokken" 0.01 1543848623 TEST Shopping 57344990085 Test ad group * / PRODUCT_TYPE_L1 = "heren" / PRODUCT_TYPE_L2 = "huissokken" / BRAND = "apollo" 0.01 1543848623 TEST Shopping 57344990085 Test ad group * / PRODUCT_TYPE_L1 = "heren" / PRODUCT_TYPE_L2 = "huissokken" / BRAND = "falke" 0.01 1543848623 TEST Shopping 57344990085 Test ad group * / PRODUCT_TYPE_L1 = "heren" / PRODUCT_TYPE_L2 = "huissokken" / BRAND = "yellow moon" 0.01 So if you see the example up, I have to loop for each row and by using this information in the row I have to add a "spgProductgroupChild". My problem is with time, the code works fine but it took long time to add all the children. You can see my code in attached file. please if you can give me some advise. Thanks -- -- =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ Also find us on our blog: https://googleadsdeveloper.blogspot.com/ =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ You received this message because you are subscribed to the Google Groups "AdWords API and Google Ads API Forum" group. To post to this group, send email to adwords-api@googlegroups.com To unsubscribe from this group, send email to adwords-api+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/adwords-api?hl=en --- You received this message because you are subscribed to the Google Groups "AdWords API and Google Ads API Forum" group. To unsubscribe from this group and stop receiving emails from it, send an email to adwords-api+unsubscr...@googlegroups.com. Visit this group at https://groups.google.com/group/adwords-api. To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/9513d3d1-c8f3-4c4b-9f01-333c3dea8b11%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Public Class AddProductPartitionTree Private tree As ProductPartitionTree = Nothing Private adgroup_Id As Long Private AdWords_User As AdWordsUser Private dProductGroups As SqlDataReader Private shopId As String Private spgProductGroupsParent As String() Private spgProductGroupsChild As String() Dim spgCPCBid ''Initializes this instance Public Sub New() shopId = "1327" dProductGroups = ReadData.syncSPProcessImportGetNewProductgroups(shopId) AdWords_User = New AdWordsUser() Dim arrIdGroup As New List(Of Long)() If dProductGroups IsNot Nothing Then While dProductGroups.Read spgCPCBid = dProductGroups("spgCPCBid") * 1000000 ''Array contains Parents[ParentName1 & dimension1, ParentName2 & dimension2, etc...] spgProductGroupsParent = dProductGroups("spgProductgroupParent").ToString().Replace("*", "").Replace("""", "").Split( New String() {"/"}, StringSplitOptions.RemoveEmptyEntries ).Where( Function(s) Not String.IsNullOrWhiteSpace(s) ).ToArray() ''Array contains child[name,Dimension] spgProductGroupsChild = dProductGroups("spgProductgroupChild").ToString().Replace("""", "").Split( New String() {"="}, StringSplitOptions.RemoveEmptyEntries).Where(Function(s) Not String.IsNullOrWhiteSpace(s)).ToArray() ''Array of arrIdGroup[newId, oldId]: to avoid fetch the tree everytime adgroup_Id = dProductGroups("spgAdgroupId") arrIdGroup.Add(adgroup_Id) If arrIdGroup.Count > 1 Then Select Case arrIdGroup(1) Case arrIdGroup(0) <> arrIdGroup(1) tree = ProductPartitionTree.DownloadAdGroupTree(AdWords_User, arrIdGroup(1)) arrIdGroup.Remove(0) Case Else arrIdGroup.Remove(arrIdGroup.Item(0)) End Select Else tree = ProductPartitionTree.DownloadAdGroupTree(AdWords_User, arrIdGroup(0)) End If ''Run the functions that we need Run() End While dProductGroups.Close() End If End Sub Private Function MyFunc() As Integer Return 0 End Function ''This function has to be fixed by adding attValue, offerId,biddingCategoryId as properties of the class up. Private Function SetDimensiontype(ByVal type As String, ByVal nodeName As String, ByVal attValue As String, ByVal offerId As String, ByVal biddingCategoryId As Long) As Object Dim typeValue As Integer = 0 Dim createdNode = Nothing ''Set type Dimension value Select Case type Case "BIDDING_CATEGORY_L1" typeValue = ProductDimensionType.BIDDING_CATEGORY_L1 Case "BIDDING_CATEGORY_L2" typeValue = ProductDimensionType.BIDDING_CATEGORY_L2 Case "BIDDING_CATEGORY_L3" typeValue = ProductDimensionType.BIDDING_CATEGORY_L3 Case "BIDDING_CATEGORY_L4" typeValue = ProductDimensionType.BIDDING_CATEGORY_L4 Case "BIDDING_CATEGORY_L5" typeValue = ProductDimensionType.BIDDING_CATEGORY_L5 Case "BRAND" typeValue = ProductDimensionType.BRAND Case "CANONICAL_CONDITION" typeValue = ProductDimensionType.CANONICAL_CONDITION Case "CUSTOM_ATTRIBUTE_0" typeValue = ProductDimensionType.CUSTOM_ATTRIBUTE_0 Case "CUSTOM_ATTRIBUTE_1" typeValue = ProductDimensionType.CUSTOM_ATTRIBUTE_1 Case "CUSTOM_ATTRIBUTE_2" typeValue = ProductDimensionType.CUSTOM_ATTRIBUTE_2 Case "CUSTOM_ATTRIBUTE_3" typeValue = ProductDimensionType.CUSTOM_ATTRIBUTE_3 Case "CUSTOM_ATTRIBUTE_4" typeValue = ProductDimensionType.CUSTOM_ATTRIBUTE_4 Case "OFFER_ID" typeValue = ProductDimensionType.OFFER_ID Case "PRODUCT_TYPE_L1" typeValue = ProductDimensionType.PRODUCT_TYPE_L1 Case "PRODUCT_TYPE_L2" typeValue = ProductDimensionType.PRODUCT_TYPE_L2 Case "PRODUCT_TYPE_L3" typeValue = ProductDimensionType.PRODUCT_TYPE_L3 Case "PRODUCT_TYPE_L3" typeValue = ProductDimensionType.PRODUCT_TYPE_L4 Case "PRODUCT_TYPE_L5" typeValue = ProductDimensionType.PRODUCT_TYPE_L5 Case "CHANNEL" typeValue = ProductDimensionType.CHANNEL Case "CHANNEL_EXCLUSIVITY" typeValue = ProductDimensionType.CHANNEL_EXCLUSIVITY End Select ''Create node If type.Contains("BIDDING_CATEGORY") Then createdNode = ProductDimensions.CreateBiddingCategory(typeValue, biddingCategoryId) ElseIf type.Contains("BRAND") Then createdNode = ProductDimensions.CreateBrand(nodeName) ElseIf type.Contains("CANONICAL_CONDITION") Then ''This option has to be completed by adding ProductCanonicalConditionCondition. createdNode = ProductDimensions.CreateCanonicalCondition(ProductCanonicalConditionCondition.[NEW]) ElseIf type.Contains("CUSTOM_ATTRIBUTE") Then createdNode = ProductDimensions.CreateCustomAttribute(typeValue, attValue) ElseIf type.Contains("OFFER_ID") Then createdNode = ProductDimensions.CreateOfferId(offerId) ElseIf type.Contains("PRODUCT_TYPE") Then createdNode = ProductDimensions.CreateType(typeValue, nodeName) ElseIf type.Contains("CHANNEL") Then ''This option has to be completed by adding ShoppingProductChannel. createdNode = ProductDimensions.CreateChannel(ShoppingProductChannel.ONLINE) ElseIf type.Contains("CHANNEL_EXCLUSIVITY") Then ''This option has to be completed by adding ShoppingProductChannelExclusivity. createdNode = ProductDimensions.CreateChannelExclusivity(ShoppingProductChannelExclusivity.SINGLE_CHANNEL) End If Return createdNode End Function ''------------------------------------------------------------------------------ 'Execute the tree operation Private Function ExecuteTreeOperations() As ProductPartitionTree Dim operations As AdGroupCriterionOperation() = tree.GetMutateOperations() Using adGroupCriterionService As AdGroupCriterionService = CType(AdWords_User.GetService( AdWordsService.v201806.AdGroupCriterionService), AdGroupCriterionService) Try adGroupCriterionService.mutate(operations) Return ProductPartitionTree.DownloadAdGroupTree(AdWords_User, adgroup_Id) Catch ex As Exception Throw New System.ApplicationException(ex.Message) End Try End Using End Function 'Does a sequence of tree transformations. Public Sub Run() ''SetRootToEmpty() PrepareWalkTree(spgProductGroupsParent, 1) End Sub Public Sub PrepareWalkTree(ByVal rowNodes As String(), ByVal counter As Integer) ''Generla variables Dim rowParentProdcutGroup Dim rowParentDimensions Dim rowParentName Dim rowParent As ProductPartitionNode Dim child As ProductPartitionNode If rowNodes.Length > 0 Then ''Create Parent: Name, level from row of db table rowParentProdcutGroup = rowNodes(0).Split("=") rowParentDimensions = rowParentProdcutGroup(0).Replace(" ", "") rowParentName = rowParentProdcutGroup(1).Replace(" ", "") rowParent = tree.Root.GetChild(SetDimensiontype(rowParentDimensions, rowParentName, Nothing, Nothing, Nothing)) ''call walktree WalkTree(rowParent, 1) Else ''Append direct child in root child = tree.Root.AddChild(SetDimensiontype(spgProductGroupsChild(0).Trim(), spgProductGroupsChild(1), Nothing, Nothing, Nothing)) child.CpcBid = spgCPCBid tree = ExecuteTreeOperations() End If End Sub Public Sub WalkTree(adwordsNode As ProductPartitionNode, ByVal counter As Integer) ''Generla variables Dim child As ProductPartitionNode Dim others As ProductPartitionNode ''Check if the node is a subdivsion If adwordsNode.IsSubdivision Then If counter <= spgProductGroupsParent.Length - 1 Then ''Loop in children of node[parent] For Each childNode As ProductPartitionNode In adwordsNode.Children ''Check if this parent has a child = elemnt in the array rowProductGroupsParent If childNode.Dimension.ToString().Contains(spgProductGroupsParent(counter).Split("=")(1).Trim()) Then ''Repeat the previous stepes until get last unit of row from db. WalkTree(childNode, counter + 1) Exit Sub End If Next Else ''When you finish the recursion add the child child = adwordsNode.AddChild(SetDimensiontype(spgProductGroupsChild(0).Trim(), spgProductGroupsChild(1), Nothing, Nothing, Nothing)) child.CpcBid = spgCPCBid tree = ExecuteTreeOperations() End If Else ''Make the node as a subdivision and append it with a child ''Dim cpcBid = adwordsNode.CpcBid adwordsNode.AsSubdivision() child = adwordsNode.AddChild(SetDimensiontype(spgProductGroupsChild(0).Trim(), spgProductGroupsChild(1), Nothing, Nothing, Nothing)) others = adwordsNode.AddChild(SetDimensiontype(spgProductGroupsChild(0).Trim(), Nothing, Nothing, Nothing, Nothing)) child.CpcBid = spgCPCBid others.CpcBid = spgCPCBid tree = ExecuteTreeOperations() End If End Sub End Class