如何解决收到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 举报,一经查实,本站将立刻删除。