[HttpGet]
public IEnumerable<string> Get(string kword)
{
var user = new AdWordsUser();
using (TargetingIdeaService targetingIdeaService = (TargetingIdeaService)user.GetService(AdWordsService.v201802.TargetingIdeaService))
{
// Create selector.
TargetingIdeaSelector selector = new TargetingIdeaSelector();
selector.requestType = RequestType.IDEAS;
selector.ideaType = IdeaType.KEYWORD;
selector.requestedAttributeTypes = new AttributeType[] {
AttributeType.KEYWORD_TEXT,
AttributeType.SEARCH_VOLUME,
AttributeType.AVERAGE_CPC,
AttributeType.COMPETITION,
AttributeType.TARGETED_MONTHLY_SEARCHES,
AttributeType.IDEA_TYPE,
};
// Set selector paging (required for targeting idea service).
Paging paging = Paging.Default;
selector.paging = paging;
// Create related to query search parameter.
var relatedToQuerySearchParameter = new RelatedToQuerySearchParameter { queries = new String[] { kword } };
var searchParameters = new SearchParameter[] { relatedToQuerySearchParameter };
//searchParameters.Add(relatedToQuerySearchParameter);
var page = new TargetingIdeaPage();
selector.searchParameters = searchParameters;
try
{
page = targetingIdeaService.get(selector);
}
catch (Exception e)
{
return new string[] { e.ToString() };
}
// Display related keywords.
if (page.entries != null && page.entries.Length > 0)
{
foreach (TargetingIdea targetingIdea in page.entries)
{
Dictionary<AttributeType, Google.Api.Ads.AdWords.v201802.Attribute> ideas =
targetingIdea.data.ToDict();
var keyword = (ideas[AttributeType.KEYWORD_TEXT] as StringAttribute).value;
var averageMonthlySearches =
(ideas[AttributeType.SEARCH_VOLUME] as LongAttribute).value;
var averageCpc = (ideas[AttributeType.AVERAGE_CPC] as MoneyAttribute).value;
var competition = (ideas[AttributeType.COMPETITION] as DoubleAttribute).value;
var monthlySearchVolume = (ideas[AttributeType.TARGETED_MONTHLY_SEARCHES] as MonthlySearchVolumeAttribute).value;
var ideaType = (ideas[AttributeType.IDEA_TYPE] as IdeaTypeAttribute).value;
var res1 = "{" +
"keyword: " + keyword +
", volume: " + averageMonthlySearches +
", averageCPC: " + averageCpc?.microAmount +
", competition: " + competition +
//", monthlySearches: " + monthlySearchVolume +
//", ideaType: " + ideaType +
"}";
return new string[] { res1 };
}
}
return new string[] { "test" };
}
}
["System.ArgumentNullException: Value cannot be null.\r\nParameter name: Looks like your application is not configured to use OAuth2 properly. Required OAuth2 parameter RefreshToken is missing. You may run Common\\\\Utils\\\\OAuth2TokenGenerator.cs to generate a default OAuth2 configuration.\r\n at Google.Api.Ads.Common.Lib.OAuth2ProviderBase.ValidateOAuth2Parameter(String propertyName, String propertyValue)\r\n at Google.Api.Ads.Common.Lib.OAuth2ProviderForApplications.RefreshAccessToken()\r\n at Google.Api.Ads.Common.Lib.OAuth2ProviderForApplications.RefreshAccessTokenIfExpiring()\r\n at Google.Api.Ads.Common.Lib.OAuth2ProviderBase.GetAuthHeader()\r\n at Google.Api.Ads.Common.Lib.OAuth2ProviderForApplications.GetAuthHeader()\r\n at Google.Api.Ads.Common.Lib.OAuth2ClientMessageInspector.BeforeSendRequest(Message& request, IClientChannel channel)\r\n at System.ServiceModel.Dispatcher.ImmutableClientRuntime.BeforeSendRequest(ProxyRpc& rpc)\r\n at System.ServiceModel.Channels.ServiceChannel.PrepareCall(ProxyOperationRuntime operation, Boolean oneway, ProxyRpc& rpc)\r\n at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)\r\n at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(MethodCall methodCall, ProxyOperationRuntime operation)\r\n at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(MethodInfo targetMethod, Object[] args)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Reflection.DispatchProxyGenerator.Invoke(Object[] args)\r\n at generatedProxy_1.get(TargetingIdeaSelector )\r\n at Google.Api.Ads.AdWords.v201802.TargetingIdeaService.get(TargetingIdeaSelector selector)\r\n at AdWordsCall.Controllers.AdWordsController.Get(String kword) in D:\\home\\site\\repository\\AdWordsCall\\Controllers\\AdWordsController.cs:line 53"]