I am trying to use TargetingIdeaService api but the results that it returns 
are very different from those of Keyword Tool UI. 
Below I attach the class .cs that I have implemented from the examples, a 
capture of the results, and another of the results of the Keyword Tool UI.
The difference is very big, especially in AttributeType.SEARCH_VOLUME.
At all times I am trying to use the same parameters in the API and in the 
Keyword Tool UI.

Does anyone have any idea what may be happening or what I may be doing 
wrong?
 
Thank you very much

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords 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 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/da470f21-ea5b-4436-973a-6577cb22e308%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
using Google.Api.Ads.AdWords.Lib;
using Google.Api.Ads.AdWords.v201710;
using Google.Api.Ads.AdWords;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace Dayvo.SEO.Keys.ReglasNegocio.Apis {

  
    public class Adwords {  
        
        public IEnumerable<Modelos.TerminoAdwordsModel> Run() {
            AdWordsUser user = new AdWordsUser();

            RelatedToQuerySearchParameter relatedToQuerySearchParameter = new RelatedToQuerySearchParameter() {
                queries = new string[] { "cecina de leon", "comprar cecina", "embutido online" },

            };
            List<SearchParameter> searchParameters = new List<SearchParameter>();

            Location location = new Location();
            location.id = 2724;    // 2724 = españa
            LocationSearchParameter locationParameter = new LocationSearchParameter() {
                locations = new Location[] { location }
            };


            Language languaje = new Language();
            languaje.id = 1003;    // 1003 = español
            LanguageSearchParameter languageParameter = new LanguageSearchParameter() {
                languages = new Language[] { languaje }
            };

            NetworkSearchParameter networkSearchParameter = new NetworkSearchParameter() {
                networkSetting = new NetworkSetting() {
                    targetGoogleSearch = true,
                    targetSearchNetwork = false,
                    targetContentNetwork = false,
                    targetPartnerSearchNetwork = false,
                }
            };

            searchParameters.Add(relatedToQuerySearchParameter);
            searchParameters.Add(locationParameter);
            searchParameters.Add(languageParameter);
            searchParameters.Add(networkSearchParameter);
            using (TargetingIdeaService targetingIdeaService = (TargetingIdeaService)user.GetService(AdWordsService.v201710.TargetingIdeaService)) {

                // Create selector.
                TargetingIdeaSelector selector = new TargetingIdeaSelector() {
                    localeCode = "es_ES",
                    currencyCode = "EUR",
                    paging = Paging.Default,
                    requestType = RequestType.STATS,
                    ideaType = IdeaType.KEYWORD,
                    requestedAttributeTypes =
                    new AttributeType[] {
                      AttributeType.KEYWORD_TEXT,
                      AttributeType.SEARCH_VOLUME,
                      AttributeType.AVERAGE_CPC,
                      AttributeType.COMPETITION,
                      AttributeType.TARGETED_MONTHLY_SEARCHES,
                    },
                    searchParameters = searchParameters.ToArray()
                };

                TargetingIdeaPage page = new TargetingIdeaPage();
                List<Modelos.TerminoAdwordsModel> salida = new List<Modelos.TerminoAdwordsModel>();
                do {
                    try {
                        page = targetingIdeaService.get(selector);
                    }
                    catch (Exception ex) { throw ex; }

                    if (page.entries != null && page.entries.Length > 0) {
                        foreach (TargetingIdea targetingIdea in page.entries) {
                            try {
                                Dictionary<AttributeType, Google.Api.Ads.AdWords.v201710.Attribute> ideas = targetingIdea.data.ToDict();

                                // nombre del termino 
                                string termino = (ideas[AttributeType.KEYWORD_TEXT] as StringAttribute).value;
                                
                                // volumen mensual estimado
                                long volumenBusquedas = (ideas[AttributeType.SEARCH_VOLUME] as LongAttribute).value;

                                // coste por click estimado
                                Money cpc = (ideas[AttributeType.AVERAGE_CPC] as MoneyAttribute).value;

                                // competencia
                                double competencia = (ideas[AttributeType.COMPETITION] as DoubleAttribute).value;

                                // volumen anual (doce meses anteriores)
                                MonthlySearchVolumeAttribute volumenAnual = (ideas[AttributeType.TARGETED_MONTHLY_SEARCHES] as MonthlySearchVolumeAttribute);
                                var volumenAnualJson = JsonConvert.SerializeObject(volumenAnual);
                                
                                Console.WriteLine(string.Format("Keyword:\"{0}\"\n\nSEARCH_VOLUME: {1}\nCPC: {2}\nCOMPETITION: {3}\n", termino, volumenBusquedas, (decimal)cpc.microAmount, competencia));
                            }
                            catch { }
                        }
                    }
                    selector.paging.IncreaseOffset();
                } while (selector.paging.startIndex < page.totalNumEntries);

                return salida;
            }
        }
    }
}

Reply via email to