DoubleClickSearch转换API请求错误

时间:2018-07-04 14:11:10

标签: c# google-cloud-platform double-click-advertising

我有以下代码使用Google.Apis.Doubleclicksearch.v2库,但在最后一行失败:

class Program
{

    private const string Account = "<<ID>>@developer.gserviceaccount.com";
    private const string P12Path = @"<<APICert>>.p12";

    static void Main(string[] args)
    {
        var certificate = new X509Certificate2(P12Path, "notasecret",
            X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet |
            X509KeyStorageFlags.Exportable);

        var credentials = new ServiceAccountCredential(
            new ServiceAccountCredential.Initializer(Account)
            {
                Scopes = new[] { DoubleclicksearchService.Scope.Doubleclicksearch }
            }.FromCertificate(certificate));

        DoubleclicksearchService service = new DoubleclicksearchService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credentials,
            ApplicationName = "MyApp",
            ApiKey = "<<APIKEY>>"
        });

        int isoDate = int.Parse(DateTime.Now.AddDays(-1).ToString("yyyymmdd"));
        var conversionRequest = service.Conversion.Get(<<AgencyID>>,
            <<AdvertiserID>>,
            <<EngineAccountID>>,
            isoDate, 10,
            isoDate, 0);

        conversionRequest.Execute();

    }
}

错误是:

  

Google.GoogleApiException:'Google.Apis.Requests.RequestError   发生了内部错误。请稍后重试您的请求。详细信息:[无效ID] [500]

2 个答案:

答案 0 :(得分:1)

日期格式有些可疑:

  

int isoDate = int.Parse(DateTime.Now.AddDays(-1).ToString(“ yyyymmdd ”)));

     

int isoDate = int.Parse(DateTime.Now.AddDays(-1).ToString(“ yyyyMMdd ”)))

此外,DS auth需要oAUth2:https://developers.google.com/doubleclick-search/v2/authorizing

答案 1 :(得分:0)

由于错误消息显示了无效ID,因此请仔细检查您的代理商,广告客户和引擎ID是否正确。如果是,那么您使用的帐户可能无权访问代理商或广告商或引擎?您可以使用具有相同帐户和代理商,广告商或引擎的其他API方法来调用吗?