Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# AdWords代码在本地主机上工作,但不在live server上工作_C#_Asp.net_Google Api_Google Ads Api - Fatal编程技术网

C# AdWords代码在本地主机上工作,但不在live server上工作

C# AdWords代码在本地主机上工作,但不在live server上工作,c#,asp.net,google-api,google-ads-api,C#,Asp.net,Google Api,Google Ads Api,情况如下:我的代码在本地主机上运行,但如果我尝试在live server上运行它,我会得到以下结果: System.ArgumentNullException:值不能为null。\r\n参数名称:看起来应用程序未配置为正确使用OAuth2。缺少必需的OAuth2参数RefreshToken。您可以运行Common\\Utils\\OAuth2TokenGenerator.cs生成默认的OAuth2配置。\r\n在Google.Api.Ads.Common.Lib.OAuth2ProviderBa

情况如下:我的代码在本地主机上运行,但如果我尝试在live server上运行它,我会得到以下结果:

System.ArgumentNullException:值不能为null。\r\n参数名称:看起来应用程序未配置为正确使用OAuth2。缺少必需的OAuth2参数RefreshToken。您可以运行Common\\Utils\\OAuth2TokenGenerator.cs生成默认的OAuth2配置。\r\n在Google.Api.Ads.Common.Lib.OAuth2ProviderBase.validateAuth2Parameter(String propertyName,String propertyValue)\r\n在Google.Api.Ads.Common.Lib.OAuth2ProviderForApplications.RefreshAccessToken()上\r\n位于Google.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.BeforeSendRequest(ProxyRpc和rpc)\r\n位于System.ServiceModel.channel.ServiceChannel.PrepareCall(ProxyOperationRuntime操作,布尔单向,ProxyRpc和rpc)\r\n位于System.ServiceModel.channel.ServiceChannel.Call(System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(MethodCall MethodCall,ProxyOperationRuntime操作)、System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(MethodCall MethodCall,ProxyOperationRuntime操作)、Object[]In、Object[]outs、TimeSpan超时)\r\n\r\n---从引发异常的上一个位置开始的堆栈结束跟踪----\r\n在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n在System.Reflection.DispatchProxyGenerator.Invoke(Object[]args)\r\n在generatedProxy\u 1.get(targetingDiaselector)\r\n在Google.Api.Ads.AdWords.v201802.TargetingDiaseService.get(TargetingIdeaSelector选择器)\r\n位于D:\home\site\repository\AdWordsCall\Controllers\AdWordsController.cs:第53行中的AdWordsCall.Controllers.AdWordsController.Get(字符串kword)

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

我的猜测是,我需要在某个地方将Url作为有效的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" };
    }
}

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

您使用什么进行身份验证?使用数据生成的json文件或使用OAuth2生成的刷新令牌?刷新令牌您可以在这里添加身份验证代码吗,您如何进行身份验证?
var user=new AdWordsUser()
如果我没记错的话,这是负责身份验证的那一行。我所有的密钥和凭证都来自
app.config
文件
["{keyword: red herring f3ae3846, volume: 4276400, averageCPC: 5647516, competition: 0.305029810905172}"]