DoubleClick Bid Manager 服務
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
您可以使用 DoubleClick Bid Manager 服務,在 Apps Script 中使用 DV360 Bid Manager API。這項 API 可讓您以程式輔助方式存取 DoubleClick Bid Manager (DBM) 報表。
參考資料
如要進一步瞭解這項服務,請參閱 DBM Reporting API 的參考說明文件。與 Apps Script 中的所有進階服務一樣,DoubleClick Bid Manager 服務使用的物件、方法和參數,都與公開 API 相同。詳情請參閱「如何判斷方法簽章」。
如要回報問題及尋求其他支援,請參閱 DBM 報表和放送支援指南。
程式碼範例
下列程式碼範例使用 API 的第 2 版。
取得查詢清單
這個範例會記錄帳戶中的所有可用查詢。
建立並執行查詢
這個範例會建立並執行新的 DBM 查詢。
擷取 DBM 查詢的最新報表
這個範例會擷取 DBM 查詢的最新報表,並記錄內容。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-31 (世界標準時間)。
[null,null,["上次更新時間: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```"]]