收到grpc错误:使用GoogleAds客户端库进行API调用时出现InvalidFlags

问题描述

我想使用Google Ads客户端进行api调用,但是在执行``googleAdsService.Search(request)''时失败,并显示以下消息:

托管调试助手“ PInvokeStackImbalance” 消息=托管调试助手'PInvokeStackImbalance':'对PInvoke函数'Grpc.Core!Grpc.Core.Internal.NativeMethods + Delegates + grpcsharp_call_start_unary_delegate :: Invoke的调用'使堆栈不平衡。这可能是因为托管的PInvoke签名与非托管的目标签名不匹配。检查PInvoke签名的调用约定和参数是否与目标非托管签名匹配。'

之后,当它进入catch块时,异常对象将保存以下信息:

grpc错误:InvalidFlags system.invalidOperationException:调用错误:InvalidFlags 在Grpc.Core.Internal.CallErrorExtensions.CheckOk(CallError callError)

下面的代码参考

GoogleAdsConfig config = new GoogleAdsConfig()
        {
            DeveloperToken = googleCredentials.developerToken,OAuth2Mode = OAuth2Flow.APPLICATION,LoginCustomerId = bpse.ParentCustomerId,oauth2clientId = googleCredentials.oauth2clientId,oauth2clientSecret = googleCredentials.oauth2clientSecret,OAuth2RefreshToken = googleCredentials.refreshToken
        };

        GoogleAdsClient client = new GoogleAdsClient(config);

        // Create the required service.
        GoogleAdsServiceClient googleAdsService =
            client.GetService(Services.V1.GoogleAdsService);

        // Creates a request that will retrieve all campaign labels with the specified
        SearchGoogleAdsRequest request = new SearchGoogleAdsRequest()
        {
            CustomerId = googleCredentials.clientCustomerId,Query = $@"SELECT
                        campaign.id,campaign.name,campaign.advertising_channel_sub_type,campaign.advertising_channel_type,metrics.clicks,metrics.conversions,metrics.conversions_value,metrics.cost_micros,metrics.impressions,segments.date
                    FROM campaign
                    WHERE segments.date BETWEEN '{startDate.ToString("yyyy-MM-dd",DateTimeFormatInfo.InvariantInfo)}' AND '{endDate.ToString("yyyy-MM-dd",DateTimeFormatInfo.InvariantInfo)}'
                    ORDER BY campaign.id",};

        var campaigns = new List<GoogleAdsRow>();

        foreach (GoogleAdsRow googleAdsRow in googleAdsService.Search(request)) //Failure in this line
            {
                // some operation
            }

.NET Framework:4.5.2 Google.Ads.GoogleAds c#软件包版本:2.9.0 Grpc.Core版本:1.21.0

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...