Code working on localhost, and not working online

125 views
Skip to first unread message

digi...@gmail.com

unread,
May 15, 2018, 5:31:24 PM5/15/18
to AdWords API and Google Ads API Forum
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"]


Peter Oliquino (AdWords API Team)

unread,
May 15, 2018, 11:50:29 PM5/15/18
to AdWords API and Google Ads API Forum
Hi,

It would seem that you may have not completely generated your OAuth2 credentials. This said, you may refer to this guide to review your steps and generate your RefreshToken. Let me know if this helps.

Thanks and regards,
Peter
AdWords API Team
Reply all
Reply to author
Forward
0 new messages