【问题标题】:Add `alt` parameter while generating reports from AdExchange Seller API从 AdExchange Seller API 生成报告时添加“alt”参数
【发布时间】:2016-11-02 11:56:41
【问题描述】:

我正在尝试从AdExchange Seller API 检索报告。 我正在使用最大允许数量的维度和指标,因此报告非常大(> 100.000 行)。根据documentation on large reports,这可以通过添加alt=media 参数来使用限制突破功能。但我不知道如何使用Google API client for PHP 添加该参数。我更愿意坚持使用 Google 官方库,但我愿意接受建议。

注意:将alt=csvalt=media 添加到optParams 不起作用,如果我删除一些维度和指标,我可以轻松访问数据。

更具体地说,我使用的是accounts_reports 资源,然后是generate 方法。查看源代码(如下所示),我看不到它可以接受alt 参数的任何地方,但我显然遗漏了一些东西。

$this->accounts_reports = new Google_Service_AdExchangeSeller_Resource_AccountsReports(
        $this,
        $this->serviceName,
        'reports',
        array(
          'methods' => array(
            'generate' => array(
              'path' => 'accounts/{accountId}/reports',
              'httpMethod' => 'GET',
              'parameters' => array(
                'accountId' => array(
                  'location' => 'path',
                  'type' => 'string',
                  'required' => true,
                ),
                'startDate' => array(
                  'location' => 'query',
                  'type' => 'string',
                  'required' => true,
                ),
                'endDate' => array(
                  'location' => 'query',
                  'type' => 'string',
                  'required' => true,
                ),
                'dimension' => array(
                  'location' => 'query',
                  'type' => 'string',
                  'repeated' => true,
                ),
                'filter' => array(
                  'location' => 'query',
                  'type' => 'string',
                  'repeated' => true,
                ),
                'locale' => array(
                  'location' => 'query',
                  'type' => 'string',
                ),
                'maxResults' => array(
                  'location' => 'query',
                  'type' => 'integer',
                ),
                'metric' => array(
                  'location' => 'query',
                  'type' => 'string',
                  'repeated' => true,
                ),
                'sort' => array(
                  'location' => 'query',
                  'type' => 'string',
                  'repeated' => true,
                ),
                'startIndex' => array(
                  'location' => 'query',
                  'type' => 'integer',
                ),
              ),
            ),
          )
        )
    );

进一步挖掘,我在Google_Service_AdExchangeSeller_Resource_AccountsReports 类中找到了这个语句。

根据查询中发送的报告请求生成 Ad Exchange 报告 参数。以 JSON 格式返回结果;以 CSV 格式检索输出 指定“alt=csv”作为查询参数。 (reports.generate)

但这究竟是如何工作的呢?据我所知,它没有。

【问题讨论】:

    标签: php google-api google-api-php-client


    【解决方案1】:

    不是真正的答案,而是渴望发表评论。

    我认为您不会让它与客户端库一起使用。客户端库是通过 Discovery Services API 生成的。它提供了有关 API 采用哪些参数的信息。出于某种原因,此alt=csv 未在该 API 的发现服务中注册。它在描述中,但未注册为参数。所以客户端库本身不会为您构建它。

    你可以看到我正在看的回复here

    一个想法是您自己对客户端库进行更改,您拥有代码。虽然手动更改客户端库并不理想,但它是可行的。 尝试添加 alt 并为其指定 CSV 值。

    我对 PHP 客户端库的内部工作没有足够的经验,但您可以在他们的论坛上将其发布为 issue。提到它不在发现中,他们可能有更简单的方法将随机参数应用于查询字符串。我对此表示怀疑,但值得一试。

    【讨论】:

    • 感谢您的回答!我很高兴有人能证实我的理智。我实际上尝试更改客户端库代码,但我没有花太多时间尝试。我可能很快再试一次。但是,我确实意识到,添加 alt=media 参数实际上会返回压缩后的 csv 文件,如文档中所述。所以我现在将使用该解决方案。谢谢回答。我会把你的标记为正确的。
    【解决方案2】:

    这应该可以通过 PHP 客户端库实现。以下示例演示了如何使用 Drive API 进行操作:

    $fileId = '0BwwA4oUTeiV1UVNwOHItT0xfa2M';
    $content = $driveService->files->get($fileId, array(
      'alt' => 'media' ));
    

    https://developers.google.com/drive/v3/web/manage-downloads#examples

    【讨论】:

    • 您好!没错,它应该。但是添加alt=media 参数实际上是有效的。据我所知,用 csv 做同样的事情。
    猜你喜欢
    • 2013-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-09
    • 2023-01-30
    • 2013-02-15
    • 2016-10-09
    相关资源
    最近更新 更多