Hi.
When I use the code locally, it works well, but when I try using it online,
I get this error: Looks like your application is not configured to use
OAuth2 properly. Required OAuth2 parameter RefreshToken is missing.
I think this is caused by not adding the online domain to the "Authorized
links" somewhere in the configuration. I remember putting the localhost
link somewhere there, but I cannot find it now.
I am using Targeting Idea Service.
Here's my code:
[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" };
}
}
Again: It works on localhost. I believe there is just some configuration
I'm missing.
Full error:
["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"]
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
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/6a8feced-5683-48cc-af98-35e350b2df05%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.