DoubleClick Bid Manager 服务
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
通过 DoubleClick Bid Manager 服务,您可以在 Apps 脚本中使用 DV360 Bid Manager API。此 API 支持以程序化方式访问 DoubleClick Bid Manager (DBM) 报告。
参考
如需详细了解此服务,请参阅 DBM Reporting API 的参考文档。与 Apps 脚本中的所有高级服务一样,DoubleClick Bid Manager 服务使用的对象、方法和参数均与公共 API 相同。如需了解详情,请参阅方法签名是如何确定的。
如需报告问题并查找其他支持,请参阅 DBM 报告和广告投放支持指南。
示例代码
以下示例代码使用 API 的版本 2。
获取查询列表
此示例会记录账号中的所有可用查询。
创建并运行查询
此示例会创建并运行新的 DBM 查询。
提取 DBM 查询的最新报告
此示例会提取 DBM 查询的最新报告并记录相应内容。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[],[],null,["# DoubleClick Bid Manager Service\n\nThe DoubleClick Bid Manager service lets you use the\n[DV360 Bid Manager API](/bid-manager)\nin Apps Script. This API provides programmatic access to DoubleClick Bid\nManager (DBM) Reporting.\n| **Note:** This is an advanced service that must be [enabled before use](/apps-script/guides/services/advanced).\n\nReference\n---------\n\nFor detailed information on this service, see the\n[reference documentation](/bid-manager/reference/rest) for the\nDBM Reporting API. Like all advanced services in Apps\nScript, the DoubleClick Bid Manager service uses the same objects, methods, and\nparameters as the public API. For more information, see [How method signatures are determined](/apps-script/guides/services/advanced#how_method_signatures_are_determined).\n\nTo report issues and find other support, see the\n[DBM Reporting and Trafficking support guide](/bid-manager/support).\n\nSample code\n-----------\n\nThe following sample code uses\n[version 2](/bid-manager/reference/rest) of the API.\n\n### Get a list of queries\n\nThis sample logs all of the queries available in the account. \nadvanced/doubleclickbidmanager.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/doubleclickbidmanager.gs) \n\n```javascript\n/**\n * Logs all of the queries available in the account.\n */\nfunction listQueries() {\n // Retrieve the list of available queries\n try {\n const queries = DoubleClickBidManager.Queries.list();\n\n if (queries.queries) {\n // Print out the ID and name of each\n for (let i = 0; i \u003c queries.queries.length; i++) {\n const query = queries.queries[i];\n console.log('Found query with ID %s and name \"%s\".',\n query.queryId, query.metadata.title);\n }\n }\n } catch (e) {\n // TODO (Developer) - Handle exception\n console.log('Failed with error: %s', e.error);\n }\n}\n```\n\n### Create and run a query\n\nThis sample creates and runs a new DBM query. \nadvanced/doubleclickbidmanager.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/doubleclickbidmanager.gs) \n\n```javascript\n/**\n * Create and run a new DBM Query\n */\nfunction createAndRunQuery() {\n let result;\n let execution;\n //We leave the default date range blank for the report run to\n //use the value defined during query creation\n let defaultDateRange = {}\n let partnerId = \"1234567\" //Replace with your Partner ID\n let query = {\n \"metadata\": {\n \"title\": \"Apps Script Example Report\",\n \"dataRange\": {\n \"range\": \"YEAR_TO_DATE\"\n },\n \"format\": \"CSV\"\n },\n \"params\": {\n \"type\": \"STANDARD\",\n \"groupBys\": [\n \"FILTER_PARTNER\",\n \"FILTER_PARTNER_NAME\",\n \"FILTER_ADVERTISER\",\n \"FILTER_ADVERTISER_NAME\",\n ],\n \"filters\": [\n {\"type\": \"FILTER_PARTNER\",\"value\": partnerId}\n ],\n \"metrics\": [\n \"METRIC_IMPRESSIONS\"\n ]\n },\n \"schedule\": {\n \"frequency\": \"ONE_TIME\"\n }\n }\n\n try {\n result = DoubleClickBidManager.Queries.create(query);\n if (result.queryId) {\n console.log('Created query with ID %s and name \"%s\".',\n result.queryId, result.metadata.title);\n execution = DoubleClickBidManager.Queries.run(defaultDateRange, result.queryId);\n if(execution.key){\n console.log('Created query report with query ID %s and report ID \"%s\".',\n execution.key.queryId, execution.key.reportId);\n }\n }\n } catch (e) {\n // TODO (Developer) - Handle exception\n console.log(e)\n console.log('Failed with error: %s', e.error);\n }\n}\n```\n\n### Fetch the most recent report for a DBM query\n\nThis sample fetches the most recent report for a DBM query and logs the content. \nadvanced/doubleclickbidmanager.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/doubleclickbidmanager.gs) \n\n```javascript\n/**\n * Fetches a report file\n */\nfunction fetchReport() {\n const queryId = '1234567'; // Replace with your query ID.\n const orderBy = \"key.reportId desc\";\n\n try {\n const report = DoubleClickBidManager.Queries.Reports.list(queryId, {orderBy:orderBy});\n if(report.reports){\n const firstReport = report.reports[0];\n if(firstReport.metadata.status.state == 'DONE'){\n const reportFile = UrlFetchApp.fetch(firstReport.metadata.googleCloudStoragePath)\n console.log(\"Printing report content to log...\")\n console.log(reportFile.getContentText())\n }\n else{\n console.log(\"Report status is %s, and is not available for download\", firstReport.metadata.status.state)\n }\n }\n\n } catch (e) {\n // TODO (Developer) - Handle exception\n console.log(e)\n console.log('Failed with error: %s', e.error);\n }\n}\n```"]]