AdWords代码在localhost上运行,但不在实时服务器上运行

时间:2018-06-06 07:33:20

标签: c# asp.net google-api google-adwords

情况如下:我的代码在localhost上运行,但如果我尝试在实时服务器上运行它,我会得到这个:

  

System.ArgumentNullException:Value不能为null。\ r \ nParameter name:看起来您的应用程序未配置为正确使用OAuth2。缺少必需的OAuth2参数RefreshToken。您可以运行Common \\ Utils \\ OAuth2TokenGenerator.cs来生成默认的OAuth2配置。\ r \ n在Google.Api.Ads.Common.Lib.OAuth2ProviderBase.ValidateOAuth2Parameter(String propertyName,String propertyValue)\ r \ n在Google上.Api.Ads.Common.Lib.OAuth2ProviderForApplications.RefreshAccessToken()\ r \ n在谷歌.Api.Ads.Common.Lib.OAuth2ProviderForApplications.RefreshAccessTokenIfExpiring()\ r \ n在Google.Api.Ads.Common.Lib.OAuth2ProviderBase .GetAuthHeader()\ r \ n在Google.Api.Ads.Common.Lib.OAuth2ProviderForApplications.GetAuthHeader()\ r \ n在Google.Api.Ads.Common.Lib.OAuth2ClientMessageInspector.BeforeSendRequest(消息和请求,IClientChannel频道) \ r \ n在System.ServiceModel.Dispatcher.ImmutableClientRuntime.BeforeRendRequest(ProxyRpc& rpc)\ r \ n在System.ServiceModel.Channels.ServiceChannel.PrepareCall(ProxyOperationRuntime操作,Boolean oneway,ProxyRpc& rpc)\ r \ n在系统中.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,P在System.ServiceModel.Channels.ServiceChannelProxy的System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(MethodCall methodCall,ProxyOperationRuntime操作)\ r \ n中的roxyOperationRuntime操作,Object [] ins,Object [] outs,TimeSpan timeout)\ r \ n。 Invoke(MethodInfo targetMethod,Object [] args)\ r \ n ---从抛出异常的先前位置开始的堆栈跟踪结束--- \ r \ n在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\ r \在System.Reflection.DispatchProxyGenerator.Invoke(Object [] args)\ r \ n at generatedProxy_1.get(TargetingIdeaSelector)\ r \ n在Google.Api.Ads.AdWords.v201802.TargetingIdeaService.get(TargetingIdeaSelector selector)\ r \ n \ n位于D:\ home \ site \ repository \ AdWordsCall \ Controllers \ AdWordsController.cs:第53行的AdWordsCall.Controllers.AdWordsController.Get(String kword)

问题是我在Azure上使用GitHub进行部署,所以它应该只抓取我需要的所有代码。

我的猜测是,在某个地方我需要将Url作为一个有效的地方包含在内,但我现在重新整理了整个密钥生成3次,但却找不到它。知道我错过了什么吗?

我的代码在这里:

[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" };
    }
}

localhost上的响应如下:

["{keyword: red herring f3ae3846, volume: 4276400, averageCPC: 5647516, competition: 0.305029810905172}"]

这是一个虚拟响应,因为它位于开发帐户下。

0 个答案:

没有答案