我正在编写一个代码来使用c#中的adwords api来获取搜索量,但是它会在行上显示错误" page = targetingIdeaService.get(selector);",下面是我的代码,I在网上找到了这个代码示例。
AdWordsAppConfig config = new AdWordsAppConfig();
config.OAuth2ClientId = "MY_OAUTH2ClientID Here";
config.OAuth2ClientSecret = "MY_OAUTH2ClientSecret Here";
AdWordsUser user = new AdWordsUser(config);
AdWordsUser user1=new AdWordsUser()
using (TargetingIdeaService targetingIdeaService = (TargetingIdeaService)user.GetService(AdWordsService.v201710.TargetingIdeaService))
{
TargetingIdeaSelector selector = new TargetingIdeaSelector();
selector.requestType = RequestType.STATS;
selector.ideaType = IdeaType.KEYWORD;
selector.requestedAttributeTypes = new AttributeType[] {
AttributeType.KEYWORD_TEXT,
AttributeType.SEARCH_VOLUME,
AttributeType.AVERAGE_CPC,
AttributeType.COMPETITION,
AttributeType.TARGETED_MONTHLY_SEARCHES
};
List<SearchParameter> searchParameters = new List<SearchParameter>();
RelatedToQuerySearchParameter relatedToQuerySearchParameter =
new RelatedToQuerySearchParameter();
relatedToQuerySearchParameter.queries = new String[] { keyword };
searchParameters.Add(relatedToQuerySearchParameter);
LanguageSearchParameter languageParameter = new LanguageSearchParameter();
Language english = new Language();
english.id = 1000;
languageParameter.languages = new Language[] { english };
searchParameters.Add(languageParameter);
NetworkSetting networkSetting = new NetworkSetting();
networkSetting.targetContentNetwork = false;
networkSetting.targetGoogleSearch = true;
networkSetting.targetPartnerSearchNetwork = false;
networkSetting.targetSearchNetwork = false;
NetworkSearchParameter networkSearchParameter = new NetworkSearchParameter() { networkSetting = networkSetting };
searchParameters.Add(networkSearchParameter);
selector.searchParameters = searchParameters.ToArray();
Paging paging = Paging.Default;
selector.paging = paging;
TargetingIdeaPage page = new TargetingIdeaPage();
try
{
do
{
page = targetingIdeaService.get(selector); // gives error on this line
if (page.entries != null && page.entries.Length > 0)
{
foreach (TargetingIdea targetingIdea in page.entries)
{
Dictionary<AttributeType, Google.Api.Ads.AdWords.v201710.Attribute> ideas =
targetingIdea.data.ToDict();
long averageMonthlySearches = (ideas[AttributeType.SEARCH_VOLUME] as LongAttribute).value;
string keywordRes = (ideas[AttributeType.KEYWORD_TEXT] as StringAttribute).value;
Money averageCpc = (ideas[AttributeType.AVERAGE_CPC] as MoneyAttribute).value;
double competition = (ideas[AttributeType.COMPETITION] as DoubleAttribute).value;
}
}
selector.paging.IncreaseOffset();
} while (selector.paging.startIndex < page.totalNumEntries);
Console.WriteLine("Number of related keywords found: {0}", page.totalNumEntries);
}
catch (AdWordsException e)
{
throw new System.ApplicationException("Failed to retrieve related keywords.", e);
}
}
请帮助我的代码出错或如何实现功能。 谢谢&amp;的问候,