שליחת בקשה לדוגמה
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
לאחר ההגדרה של הכול, צריך לוודא שאפשר לשלוח דוגמה
לשלוח בקשה ל-Search Ads 360 API. דוגמת הקוד הבאה ממחישה איך
לשלוח בקשה אסינכרונית
לרשימת הקמפיינים בחשבון המפרסם שלכם. אם הבקשה
הפעולה בוצעה בהצלחה, תקבלו תשובה מ-Search Ads 360 API שהדוח נוצר
אך לא מוכן (כלומר מכיוון שבקשות אסינכרוניות דורשות בקשות נוספות כדי
להוריד דוח בפועל).
עליך לציין אסימון גישה משלך מסוג OAuth 2.0 ומזהה סוכנות משלך ב
לבקשה. איפה מופיע מזהה הסוכנות:
- נכנסים לממשק המשתמש של Search Ads 360.
- מזהי הסוכנות והמפרסם מוצגים בכתובת ה-URL, מיד אחרי
ay=
ותחילית av=
. לדוגמה:
https://searchads.google.com/ds/cm/cm/cm/cm#campaigns.ay=123456789012345678;av=123456789012345678;
JSON
POST https://www.googleapis.com/doubleclicksearch/v2/reports
Authorization: Bearer your OAuth 2.0 access token
Content-type: application/json
{
"reportScope": {
"agencyId": "your agency ID",
"advertiserId": "your advertiser ID"
},
"reportType": "campaign",
"columns": [
{ "columnName": "campaignId" },
{ "columnName": "campaign" }
],
"downloadFormat": "csv",
"maxRowsPerFile": 6000000,
"statisticsCurrency": "agency"
}
כדי לשלוח את הבקשה, צריך להשתמש בסקריפט של כלי השירות של Search Ads 360
כדי לשלוח בקשת JSON POST גולמית, אפשר להשתמש ב-sa360Api.py
סקריפט באופן הבא:
- מעתיקים את אובייקט ה-JSON לדוגמה (כל מה שמופיע בין השניים, כולל
סוגריים מסולסלים) בקובץ טקסט חדש בשם
request.txt
.
- משנים את מזהה הסוכנות שמופיע בקוד ה-JSON למזהה הסוכנות שלכם.
- מסירים תגובות, למשל
// The date column segments the report by individual days.
- מרכיבים את פרטי הכניסה של OAuth 2.0 במחרוזת אחת שמופרדת בפסיקים
עוקב:
client-ID,client-secret,refresh-token
(זו אותה המחרוזת ש-sa360Api.py
יוצרת כשמריצים את sa360Api.py
--login
, כפי שמתואר בהגדרה
הרשאה).
- מפעילים את
sa360Api.py
באופן הבא:
sa360Api.py --cred
CREDENTIALS --server API-method --post < request.txt
בפקודה שלמעלה, מחליפים ב-CREDENTIALS
את המחרוזת שהרכבתם בשלב הקודם.
מחליפים את השם של שיטת ה-POST בתיבה שלמטה בשדה API-method
.
לדוגמה:
sa360Api.py --cred
123456789123.apps.googleusercontent.com,ABCDEFGHIJKLMNOPQR_abcdef,1/HIJklM01OPQR23NOP456rst890uvw
--server https://www.googleapis.com/doubleclicksearch/v2/reports/generate --post < request.txt
Java
import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo;
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.services.doubleclicksearch.Doubleclicksearch;
import com.google.api.services.doubleclicksearch.model.ReportApiColumnSpec;
import com.google.api.services.doubleclicksearch.model.ReportRequest;
import com.google.api.services.doubleclicksearch.model.ReportRequest.ReportScope;
import com.google.api.services.doubleclicksearch.model.ReportRequest.TimeRange;
import java.io.IOException;
import java.util.Arrays;
/**
* Creates a campaign report request, submits the report, and returns the report ID.
*/
private static String createReport(Doubleclicksearch service) throws IOException {
try {
return service.reports().request(createSampleRequest()).execute().getId();
} catch (GoogleJsonResponseException e) {
System.err.println("Report request was rejected.");
for (ErrorInfo error : e.getDetails().getErrors()) {
System.err.println(error.getMessage());
}
System.exit(e.getStatusCode());
return null; // Unreachable code.
}
}
/**
* Returns a simple static request that lists the ID and name of all
* campaigns under agency 20100000000000895 and advertiser 21700000000011523.
* Substitute your own agency ID and advertiser IDs for the IDs in this sample.
*/
private static ReportRequest createSampleRequest() {
return new ReportRequest()
.setReportScope(new ReportScope()
.setAgencyId(20100000000000895L) // Replace with your ID
.setAdvertiserId(21700000000011523L)) // Replace with your ID
.setReportType("campaign")
.setColumns(Arrays.asList(
new ReportApiColumnSpec[] {
new ReportApiColumnSpec().setColumnName("campaignId"),
new ReportApiColumnSpec().setColumnName("campaign")
}))
.setTimeRange(new TimeRange()
.setStartDate("2014-05-01")
.setEndDate("2014-05-01"))
.setDownloadFormat("csv")
.setStatisticsCurrency("usd")
.setMaxRowsPerFile(5000000);
}
.NET
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Auth.OAuth2.Flows;
using api = Google.Apis.Doubleclicksearch.v2;
/// <summary>
/// Creates a campaign report request, submits the report, and returns the report ID.
/// </summary>
/// <param name="service">Search Ads API service.</param>
private static string CreateReport(api.DoubleclicksearchService service)
{
var req = service.Reports.Request(CreateSampleRequest());
var report = req.Execute();
Console.WriteLine("Created report: ID={0}", report.Id);
return report.Id;
}
/// <summary>
/// Returns a simple static request that lists the ID and name of all
/// campaigns under agency 20100000000000895 and advertiser 21700000000011523.
/// Substitute your own agency ID and advertiser IDs for the IDs in this sample.
/// </summary>
private static api.Data.ReportRequest CreateSampleRequest()
{
return new api.Data.ReportRequest
{
ReportScope = new api.Data.ReportRequest.ReportScopeData
{
AgencyId = 20100000000000895,
AdvertiserId = 21700000000011523,
},
ReportType = "campaign",
Columns = new List<api.Data.ReportRequest.ColumnsData>
{
new api.Data.ReportRequest.ColumnsData
{
ColumnName = "campaignId",
},
new api.Data.ReportRequest.ColumnsData
{
ColumnName = "campaign",
},
},
TimeRange = new api.Data.ReportRequest.TimeRangeData
{
StartDate = "2014-01-01",
EndDate = "2014-01-31",
},
DownloadFormat = "csv",
StatisticsCurrency = "usd",
MaxRowsPerFile = 5000000,
};
}
Python
def generate_report(service):
"""Generate and print sample report.
Args:
service: An authorized Doubleclicksearch service. See Set Up Your Application.
"""
request = service.reports().request(
body =
{
"reportScope": {
"agencyId": "your agency ID",
"advertiserId": "your advertiser ID"
},
"reportType": "campaign",
"columns": [
{ "columnName": "campaignId" },
{ "columnName": "campaign" }
],
"downloadFormat": "csv",
"maxRowsPerFile": 6000000,
"statisticsCurrency": "agency"
}
)
pprint.pprint(request.execute())
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2024-08-21 (שעון UTC).
[null,null,["עדכון אחרון: 2024-08-21 (שעון UTC)."],[[["\u003cp\u003eThis page guides you through sending a test request to the Search Ads 360 API to confirm your setup.\u003c/p\u003e\n"],["\u003cp\u003eThe example request fetches a list of campaigns under a specified advertiser and agency, returning a confirmation upon success.\u003c/p\u003e\n"],["\u003cp\u003eYou need to replace placeholder values with your actual agency and advertiser IDs, along with your OAuth 2.0 access token.\u003c/p\u003e\n"],["\u003cp\u003eCode samples in JSON, Java, .NET, and Python demonstrate how to construct and send the API request using different methods.\u003c/p\u003e\n"],["\u003cp\u003eFor successful execution, utilize the provided Search Ads 360 utility script or adapt the code samples to your environment.\u003c/p\u003e\n"]]],["The core content demonstrates sending an asynchronous request to the Search Ads 360 API to list campaigns under a specified advertiser. This involves using an OAuth 2.0 access token and agency ID. The request, illustrated in JSON, Java, .NET, and Python, defines the report scope, type (campaign), columns (campaignId, campaign), format (csv), and other parameters. It uses either the Search Ads 360 utility script or direct `POST` method. Successful requests return a report creation confirmation, with further requests needed to access the full report.\n"],null,["# Send a Sample Request\n\nAfter you've set everything up, make sure you can successfully send a sample\nrequest to the Search Ads 360 API. The following code sample demonstrates how to\nsend an [asynchronous request](/search-ads/v2/how-tos/reporting/asynchronous-requests)\nfor the list of campaigns under your advertiser. If the request\nis successful, you'll get a response from the Search Ads 360 API saying that the report is created\nbut not ready (this is because asynchronous requests require additional requests to\nactually download a report).\n\n\nYou'll need to specify your own OAuth 2.0 access token and your own agency ID in\nthe request. To find your agency ID:\n\n1. Visit the [Search Ads 360 UI](http://searchads.google.com/ds/cm/cm/).\n2. Your agency and advertiser IDs are displayed in the URL, just after the `ay=` and `av=` prefix. For example: \n `https://searchads.google.com/ds/cm/cm/cm/cm#campaigns.ay=`**123456789012345678** `;av=`**123456789012345678**`;`\n\n### JSON\n\n```gdscript\nPOST https://www.googleapis.com/doubleclicksearch/v2/reports\nAuthorization: Bearer your OAuth 2.0 access token\nContent-type: application/json\n\n{\n \"reportScope\": {\n \"agencyId\": \"your agency ID\",\n \"advertiserId\": \"your advertiser ID\"\n },\n \"reportType\": \"campaign\",\n \"columns\": [\n { \"columnName\": \"campaignId\" },\n { \"columnName\": \"campaign\" }\n ],\n \"downloadFormat\": \"csv\",\n \"maxRowsPerFile\": 6000000,\n \"statisticsCurrency\": \"agency\"\n}\n```\n\n#### Use the Search Ads 360 utility script to send this request\n\n\nTo send a raw JSON POST request, you can use the [sa360Api.py\nscript](/search-ads/v2/prereqs#ds3py) as follows:\n\n1. Copy the example JSON object (everything between and including the two curly brackets) into a new text file named `request.txt`.\n2. Change the agency ID that's in the JSON code to your own agency ID.\n3. Remove any comments, such as `// The date column segments the report by individual days.`\n4. Assemble your OAuth 2.0 credentials into a single, comma-delimited string as follows: \n `client-ID,client-secret,refresh-token` \n (This is the same string that `sa360Api.py` outputs when you run `sa360Api.py\n --login` as described in [Set Up\n Authorization](/search-ads/v2/authorizing).)\n5. Invoke `sa360Api.py` as follows: \n `sa360Api.py --cred\n `*CREDENTIALS*` --server `*API-method*` --post \u003c request.txt\n ` \n In the command above, substitute the string you assembled in the previous step for *CREDENTIALS*. \n Substitute the name of the POST method in the box below for *API-method*.\n\n\n For example: \n `sa360Api.py --cred\n 123456789123.apps.googleusercontent.com,ABCDEFGHIJKLMNOPQR_abcdef,1/HIJklM01OPQR23NOP456rst890uvw\n --server https://www.googleapis.com/doubleclicksearch/v2/reports/generate --post \u003c request.txt`\n\n### Java\n\n```python\nimport com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo;\nimport com.google.api.client.googleapis.json.GoogleJsonResponseException;\nimport com.google.api.services.doubleclicksearch.Doubleclicksearch;\nimport com.google.api.services.doubleclicksearch.model.ReportApiColumnSpec;\nimport com.google.api.services.doubleclicksearch.model.ReportRequest;\nimport com.google.api.services.doubleclicksearch.model.ReportRequest.ReportScope;\nimport com.google.api.services.doubleclicksearch.model.ReportRequest.TimeRange;\n\nimport java.io.IOException;\nimport java.util.Arrays;\n\n /**\n * Creates a campaign report request, submits the report, and returns the report ID.\n */\n private static String createReport(Doubleclicksearch service) throws IOException {\n try {\n return service.reports().request(createSampleRequest()).execute().getId();\n } catch (GoogleJsonResponseException e) {\n System.err.println(\"Report request was rejected.\");\n for (ErrorInfo error : e.getDetails().getErrors()) {\n System.err.println(error.getMessage());\n }\n System.exit(e.getStatusCode());\n return null; // Unreachable code.\n }\n }\n\n /**\n * Returns a simple static request that lists the ID and name of all\n * campaigns under agency 20100000000000895 and advertiser 21700000000011523.\n * Substitute your own agency ID and advertiser IDs for the IDs in this sample.\n */\n private static ReportRequest createSampleRequest() {\n return new ReportRequest()\n .setReportScope(new ReportScope()\n .setAgencyId(20100000000000895L) // Replace with your ID\n .setAdvertiserId(21700000000011523L)) // Replace with your ID\n .setReportType(\"campaign\")\n .setColumns(Arrays.asList(\n new ReportApiColumnSpec[] {\n new ReportApiColumnSpec().setColumnName(\"campaignId\"),\n new ReportApiColumnSpec().setColumnName(\"campaign\")\n }))\n .setTimeRange(new TimeRange()\n .setStartDate(\"2014-05-01\")\n .setEndDate(\"2014-05-01\"))\n .setDownloadFormat(\"csv\")\n .setStatisticsCurrency(\"usd\")\n .setMaxRowsPerFile(5000000);\n }\n```\n\n### .NET\n\n```gdscript\nusing System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Threading;\n\nusing Google.Apis.Auth.OAuth2;\nusing Google.Apis.Auth.OAuth2.Flows;\nusing api = Google.Apis.Doubleclicksearch.v2;\n\n/// \u003csummary\u003e\n/// Creates a campaign report request, submits the report, and returns the report ID.\n/// \u003c/summary\u003e\n/// \u003cparam name=\"service\"\u003eSearch Ads API service.\u003c/param\u003e\nprivate static string CreateReport(api.DoubleclicksearchService service)\n{\n var req = service.Reports.Request(CreateSampleRequest());\n var report = req.Execute();\n Console.WriteLine(\"Created report: ID={0}\", report.Id);\n return report.Id;\n}\n\n/// \u003csummary\u003e\n/// Returns a simple static request that lists the ID and name of all\n/// campaigns under agency 20100000000000895 and advertiser 21700000000011523.\n/// Substitute your own agency ID and advertiser IDs for the IDs in this sample.\n/// \u003c/summary\u003e\nprivate static api.Data.ReportRequest CreateSampleRequest()\n{\n return new api.Data.ReportRequest\n {\n ReportScope = new api.Data.ReportRequest.ReportScopeData\n {\n AgencyId = 20100000000000895,\n AdvertiserId = 21700000000011523,\n },\n ReportType = \"campaign\",\n Columns = new List\u003capi.Data.ReportRequest.ColumnsData\u003e\n {\n new api.Data.ReportRequest.ColumnsData\n {\n ColumnName = \"campaignId\",\n },\n new api.Data.ReportRequest.ColumnsData\n {\n ColumnName = \"campaign\",\n },\n },\n TimeRange = new api.Data.ReportRequest.TimeRangeData\n {\n StartDate = \"2014-01-01\",\n EndDate = \"2014-01-31\",\n },\n DownloadFormat = \"csv\",\n StatisticsCurrency = \"usd\",\n MaxRowsPerFile = 5000000,\n };\n}\n```\n\n### Python\n\n```gdscript\ndef generate_report(service):\n \"\"\"Generate and print sample report.\n\n Args:\n service: An authorized Doubleclicksearch service. See /search-ads/v2/configure.\n \"\"\"\n request = service.reports().request(\n body =\n {\n \"reportScope\": {\n \"agencyId\": \"your agency ID\",\n \"advertiserId\": \"your advertiser ID\"\n },\n \"reportType\": \"campaign\",\n \"columns\": [\n { \"columnName\": \"campaignId\" },\n { \"columnName\": \"campaign\" }\n ],\n \"downloadFormat\": \"csv\",\n \"maxRowsPerFile\": 6000000,\n \"statisticsCurrency\": \"agency\"\n }\n )\n\n pprint.pprint(request.execute())\n```"]]