অ্যাসিঙ্ক্রোনাস অনুরোধ

নতুন Search Ads 360 Reporting API এখন উপলব্ধ। নতুন API কাস্টম রিপোর্ট তৈরি করতে এবং আপনার রিপোর্টিং অ্যাপ্লিকেশন এবং প্রক্রিয়াগুলিতে ডেটা সংহত করার জন্য উন্নত নমনীয়তা প্রদান করে। নতুন Search Ads 360 Reporting API- এ স্থানান্তরিত ও ব্যবহার সম্পর্কে আরও জানুন।

যেহেতু বড় রিপোর্টের জন্য অনুরোধগুলি তৈরি হতে কিছুটা সময় লাগতে পারে, তাই Search Ads 360 API রিপোর্টের অনুরোধ এবং ডাউনলোড করার জন্য একটি অ্যাসিঙ্ক্রোনাস কৌশল প্রদান করে। এই কৌশলটির সাহায্যে, আপনি একটি প্রাথমিক অনুরোধ পাঠান যা রিপোর্টে আপনি যে ডেটা চান তা নির্দিষ্ট করে এবং তারপর অনুসন্ধান বিজ্ঞাপন 360 রিপোর্ট তৈরি করা শেষ না হওয়া পর্যন্ত অতিরিক্ত ভোটের অনুরোধ পাঠান। রিপোর্টের আকারের উপর নির্ভর করে, Search Ads 360 ডেটাকে একাধিক ফাইলে বিভক্ত করে। একবার রিপোর্ট তৈরি হয়ে গেলে, আপনি প্রতিটি রিপোর্ট ফাইল ডাউনলোড করার জন্য অনুরোধ পাঠান। আপনি যদি কম পরিমাণে ডেটার অনুরোধ করেন, আপনি শুধুমাত্র একটি সিঙ্ক্রোনাস অনুরোধ পাঠাতে পারেন৷

একটি অ্যাসিঙ্ক্রোনাস অনুরোধ করতে

  1. রিপোর্টে আপনি যে ধরনের ডেটা চান তা উল্লেখ করতে Reports.request() এ কল করুন। আপনি যে ধরনের ডেটার অনুরোধ করতে পারেন তার জন্য রিপোর্টের ধরন দেখুন।

    Search Ads 360 অনুরোধটি যাচাই করে এবং একটি রিপোর্ট আইডি ফেরত দেয়—এই অনুরোধের জন্য একটি অনন্য শনাক্তকারী।

  2. রিপোর্ট আইডি দিয়ে Reports.get() এ কল করুন।

    Search Ads 360 এর প্রতিক্রিয়া ইঙ্গিত করে:

    • প্রতিবেদনটি ডাউনলোডের জন্য প্রস্তুত কিনা।
    • রিপোর্ট প্রস্তুত হলে, রিপোর্ট ডাউনলোড করার জন্য এক বা একাধিক URL।
  3. এনকোড করা রিপোর্ট ফাইল ডাউনলোড করতে Reports.getFile() এ কল করুন, অথবা সরাসরি URL থেকে ডাউনলোড করুন।

    Search Ads 360 একটি UTF-8 এনকোড করা ফাইলে রিপোর্ট প্রদান করে।

তারা প্রস্তুত কিনা তা দেখার জন্য আমার কত ঘন ঘন পোল রিপোর্ট করা উচিত?

একটি রিপোর্ট তৈরি করতে Search Ads 360-এর কতটা সময় লাগবে তা বেশিরভাগই রিপোর্টে থাকা ডেটার উপর নির্ভর করে। প্রতি মিনিটে একবার রিপোর্ট স্ট্যাটাসের জন্য পোলিং করার চেষ্টা করুন, এবং তারপরে ফ্রিকোয়েন্সি সামঞ্জস্য করুন যদি আপনার গড় রিপোর্ট অনুরোধটি শেষ হতে উল্লেখযোগ্যভাবে কম বা বেশি সময় নেয়।

একাধিক ফাইলে অ্যাসিঙ্ক্রোনাস রিপোর্ট বিভক্ত করা

একটি অ্যাসিঙ্ক্রোনাস অনুরোধের প্রতিক্রিয়া হিসাবে, Search Ads 360 স্বয়ংক্রিয়ভাবে বড় রিপোর্টগুলিকে একাধিক ফাইলে বিভক্ত করে। সর্বোচ্চ ফাইলের আকার নির্দিষ্ট করতে Reports.request.maxRowsPerFile প্রপার্টি ব্যবহার করুন। প্রতিটি ফলাফলের রিপোর্ট ফাইলে সর্বাধিক maxRowsPerFile রিপোর্ট সারি (হেডার গণনা না) থাকার নিশ্চয়তা রয়েছে। প্রতিটি ফাইলের জন্য একটি আলাদা URL তৈরি করা হয় এবং Reports.get() এর প্রতিক্রিয়া হিসাবে ফিরে আসে। রিপোর্ট ফাইল ডাউনলোড করার বিষয়ে তথ্যের জন্য, রিপোর্ট ডাউনলোড করুন দেখুন।

CSV রিপোর্টের জন্য, প্রতিটি ফাইলে হেডার পুনরাবৃত্তি করা হয়।

দ্রষ্টব্য : API অ্যাসিঙ্ক্রোনাস অনুরোধের জন্য পেজিং সমর্থন করে না। অর্থাৎ, আপনি কোন সারিগুলি কোন রিপোর্ট ফাইলে থাকতে চান তা নির্দিষ্ট করতে পারবেন না। ফাইলগুলির মধ্যে সারিগুলিকে যেভাবে বিভক্ত করা হয় তা নির্বিচারে, এবং একই প্রতিবেদন আবার চালানো হলে তা পরিবর্তিত হতে পারে।

অ্যাসিঙ্ক্রোনাস উদাহরণ

নীচে অ্যাসিঙ্ক্রোনাস কৌশল ব্যবহার করে নমুনা অনুরোধ এবং প্রতিক্রিয়া রয়েছে৷

JSON

POST  https://www.googleapis.com/doubleclicksearch/v2/reports
Authorization: Bearer your OAuth 2.0 access token
Content-type: application/json

{
  "reportScope": {
    "agencyId": "12300000000000456", // Replace with your ID
    "advertiserId": "21700000000011523", // Replace with your ID
  },
  "reportType": "keyword",              // This report covers all keywords in the
                                        // advertiser specified in reportScope.
  "columns": [
    { "columnName": "campaignId" },     // Here are some attribute columns available for keyword
    { "columnName": "keywordText" },    // reports.
    { "columnName": "keywordLandingPage" },

    { "columnName": "date" },           // The date column segments the report by individual days.

    { "columnName": "dfaRevenue" },     // Here are some metric columns available for keyword
    {                                   // reports
      "columnName": "visits",
      "startDate": "2013-01-01",        // Each metric column can optionally specify its own start
      "endDate": "2013-01-31",          // and end date; by default the report timeRange is used.
      "headerText": "visits last month" // Every column can optionally specify a headerText, which
                                        // changes the name of the column in the report.
    }
  ],
  "timeRange" : {
    "startDate" : "2012-05-01",         // Dates are inclusive and specified in YYYY-MM-DD format.
    "endDate" : "2012-05-02"

    // Alternatively, try the "changedMetricsSinceTimestamp" or "changedAttributesSinceTimestamp"
    // options. See Incremental reports.

  },
  "filters": [
    {
      "column" : { "columnName": "keywordLandingPage" },
      "operator" : "startsWith",
      "values" : [                      // With this filter, only keywords with landing pages
        "http://www.foo.com",           // rooted at www.foo.com or www.bar.com are returned.
        "http://www.bar.com"            // See Filtered reports.
      ]
    }
  ],
  "downloadFormat": "csv",
  "maxRowsPerFile": 6000000,            // Required. See Splitting reports into multiple files.
  "statisticsCurrency": "agency",       // Required. See Currency for statistics.
  "verifySingleTimeZone": false,        // Optional. Defaults to false. See Time zone.
  "includeRemovedEntities": false           // Optional. Defaults to false.
}
          

জাভা

/**
 * 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.
  }
}

/**
 * Creates a simple static request that lists the ID and name of all
 * campaigns under agency 12300000000000456 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(12300000000000456L) // 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("2012-05-01")
          .setEndDate("2012-05-01"))
      .setDownloadFormat("csv")
      .setStatisticsCurrency("usd")
      .setMaxRowsPerFile(5000000);
}

.নেট

এই ফাংশনটি একটি প্রতিবেদন তৈরি করে যা একটি বিজ্ঞাপনদাতার অধীনে প্রচারাভিযানের তালিকা করে এবং reportId ফেরত টোকেন বরাদ্দ করে।
using api = Google.Apis.Doubleclicksearch.v2;

/// <summary>
/// Creates a report with a sample request and returns the report ID.
/// </summary>
/// <param name="service">Search Ads 360 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 an advertiser.
/// 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 = 12300000000000456, // Replace with your ID
            AdvertiserId = 21700000000011523 // Replace with your ID
        },
        ReportType = ReportType.CAMPAIGN,
        Columns = new List<api.Data.ReportApiColumnSpec>
        {
            new api.Data.ReportApiColumnSpec
            {
                ColumnName = "campaignId",
            },
            new api.Data.ReportApiColumnSpec
            {
                ColumnName = "campaign",
            },
        },
        TimeRange = new api.Data.ReportRequest.TimeRangeData
        {
            StartDate = "2015-01-01",
            EndDate = "2015-01-07",
        },
        DownloadFormat = "csv",
        StatisticsCurrency = "usd",
        MaxRowsPerFile = 5000000,
    };
}

পাইথন

def request_report(service):
  """Request sample report and print the report ID that DS returns. See Set Up Your Application.

  Args:
    service: An authorized Doubleclicksearch service.
  Returns:
    The report id.
  """
  request = service.reports().request(
      body=
      {
        "reportScope": {
            "agencyId": "12300000000000456", // Replace with your ID
            "advertiserId": "21700000000011523", // Replace with your ID
            "engineAccountId": "700000000073991" // Replace with your ID
            },
        "reportType": "keyword",
        "columns": [
            { "columnName": "campaignId" },
            { "columnName": "keywordText" },
            { "columnName": "keywordLandingPage" },

            { "columnName": "date" },

            { "columnName": "dfaRevenue" },
            {
              "columnName": "visits",
              "startDate": "2013-01-01",
              "endDate": "2013-01-31",
              "headerText": "visits last month"
            }
          ],
          "timeRange" : {
            "startDate" : "2012-05-01",
            "endDate" : "2012-05-02"
          },
          "filters": [
            {
              "column" : { "columnName": "keywordLandingPage" },
              "operator" : "startsWith",
              "values" : [
                "http://www.foo.com",
                "http://www.bar.com"
              ]
            }
          ],
          "downloadFormat": "csv",
          "maxRowsPerFile": 6000000,
          "statisticsCurrency": "agency",
          "verifySingleTimeZone": "false",
          "includeRemovedEntities": "false"
        }
  )

  json_data = request.execute()
  return json_data['id']

যদি বৈধতা সফল হয়

প্রতিবেদনটি বৈধতা পাস করলে, Search Ads 360 একটি রিপোর্ট আইডি প্রদান করে। Search Ads 360 মুদ্রা কোড এবং টাইম জোন সংক্রান্ত মেটাডেটাও প্রদান করে।

{
  "kind": "adsdartsearch#report",
  "id": "MTMyNDM1NDYK",                      // This is the report id.
  "isReportReady": false,                    // The report is not finished generating.

  "request": {                               // The request that created this report.
    ...
  },

  "statisticsCurrencyCode": "CAD",           // The currency used for statistics. E.g., if
                                             // advertiser currency was requested, this would be
                                             // currency code of the advertiser in scope.

  "statisticsTimeZone": "America/New_York"   // If all statistics in the report were sourced from
                                             // a single time zone, this would be it. If
                                             // verifySingleTimeZone was set to true in the request,
                                             // then this field will always be populated (or the
                                             // request will fail).
}
      

বৈধতা ব্যর্থ হলে

যদি রিপোর্টটি যাচাইকরণ না করে, তাহলে Search Ads 360 একটি ত্রুটির বস্তু সহ HTTP 400 প্রতিক্রিয়া প্রদান করে। উদাহরণস্বরূপ, উপরের উদাহরণ অনুরোধটি একটি বাস্তব সংস্থা নির্দিষ্ট করেনি:

{
 "error": {
   "code": 400,
   "message": "statisticsCurrency: the agency in scope does not have a valid currency. Please make sure the agency is properly initialized in Search Ads 360."
 }
}

রিপোর্ট স্ট্যাটাস জন্য পোল

রিপোর্ট আইডি সহ Report.Get() কে কল করুন।

JSON

GET https://www.googleapis.com/doubleclicksearch/v2/reports/MTMyNDM1NDYK
          

জাভা

/**
 * Polls the reporting API with the reportId until the report is ready.
 * Returns the report.
 */
private static Report pollUntilReportIsFinished(Doubleclicksearch service, String reportId)
    throws IOException, InterruptedException {
  long delay = 1;
  while (true) {
    Report report = null;
    try {
      report = service.reports().get(reportId).execute();
    } catch (GoogleJsonResponseException e) {
      System.err.println("Report generation has failed.");
      System.exit(e.getStatusCode());
    }
    if (report.getIsReportReady()) {
      return report;
    }
    System.out.format("Report %s is not ready - waiting %s seconds.%n", reportId, delay);
    Thread.sleep(TimeUnit.SECONDS.toMillis(delay));
    delay = delay + delay; // Double the delay for the next iteration.
  }
}

.নেট

using api = Google.Apis.Doubleclicksearch.v2;

/// <summary>
/// Polls until the report with the given ID completes.
/// </summary>
/// <param name="service">Search Ads 360 API service.</param>
/// <param name="reportId">Report ID to poll.</param>
/// <exception cref="ApplicationException">
/// Thrown when the report completes, but has failed.
/// </exception>
private static api.Data.Report PollUntilReportIsFinished(
    api.DoubleclicksearchService service,
    string reportId)
{
    TimeSpan delay = TimeSpan.FromSeconds(1);
    while (true)
    {
        api.Data.Report report;
        try
        {
            report = service.Reports.Get(reportId).Execute();
        }
        catch (Google.GoogleApiException ex)
        {
            throw new ApplicationException("Report generation failed", ex);
        }
        if (report.IsReportReady.GetValueOrDefault(false))
        {
            return report;
        }
        Console.WriteLine("Report is not ready - waiting {0}", delay);
        Thread.Sleep(delay);
        delay = delay.Add(delay); // Double the delay for the next iteration.
    }
}

পাইথন

import pprint
import simplejson
from googleapiclient.errors import HttpError

def poll_report(service, report_id):
  """Poll the API with the reportId until the report is ready, up to ten times.

  Args:
    service: An authorized Doubleclicksearch service.
    report_id: The ID DS has assigned to a report.
  """
  for _ in xrange(10):
    try:
      request = service.reports().get(reportId=report_id)
      json_data = request.execute()
      if json_data['isReportReady']:
        pprint.pprint('The report is ready.')

        # For large reports, DS automatically fragments the report into multiple
        # files. The 'files' property in the JSON object that DS returns contains
        # the list of URLs for file fragment. To download a report, DS needs to
        # know the report ID and the index of a file fragment.
        for i in range(len(json_data['files'])):
          pprint.pprint('Downloading fragment ' + str(i) + ' for report ' + report_id)
          download_files(service, report_id, str(i)) # See Download the report.
        return

      else:
        pprint.pprint('Report is not ready. I will try again.')
        time.sleep(10)
    except HttpError as e:
      error = simplejson.loads(e.content)['error']['errors'][0]

      # See Response Codes
      pprint.pprint('HTTP code %d, reason %s' % (e.resp.status, error['reason']))
      break

যদি রিপোর্ট প্রস্তুত না হয়

রিপোর্ট প্রস্তুত না হলে, Search Ads 360 একটি HTTP 202 প্রতিক্রিয়া প্রদান করে এবং isReportReady ক্ষেত্রটি মিথ্যা।

{
  "kind": "doubleclicksearch#report",
  "id": "MTMyNDM1NDYK",
  "isReportReady": false,
  "request": {
    ...
  },
  ...
}
      

রিপোর্ট তৈরি হলে

প্রতিবেদনটি সম্পূর্ণ হয়ে গেলে এবং ডাউনলোডের জন্য প্রস্তুত হলে, isReportReady ক্ষেত্রটি সত্য। প্রতিক্রিয়াটিতে একটি অতিরিক্ত ক্ষেত্র, files রয়েছে, যেটিতে প্রতিবেদন ফাইলগুলি ডাউনলোড করার জন্য URL রয়েছে৷

{
  "kind": "doubleclicksearch#report",
  "id": "MTMyNDM1NDYK",
  "isReportReady": true,
  "request": {
    ...
  },
  ...
  "rowCount": 1329,        // Total rows in the report, not counting headers.
  "files": [
    {
      "url": "https://www.googleapis.com/doubleclicksearch/v2/reports/MTMyNDM1NDYK/files/0"
      "byteCount": "10242323"
    },
    {
      "url": "https://www.googleapis.com/doubleclicksearch/v2/reports/MTMyNDM1NDYK/files/1"
      "byteCount": "10242323"
    }
  ],
}
      

রিপোর্ট তৈরি করতে ব্যর্থ হলে

যদি Search Ads 360 একটি রিপোর্ট তৈরি করতে না পারে, তাহলে এটি একটি বিবরণ সহ একাধিক HTTP এরর কোডের একটি প্রদান করে।

{
  "error" : {
   "code" : 410,            // Or other error codes.
   "message" : "Processing was halted on the backend and will not continue."
  }
}
      

অনুসন্ধান বিজ্ঞাপন 360 ফেরত দিতে পারে এমন ত্রুটিগুলির তালিকার জন্য প্রতিক্রিয়া কোডগুলি দেখুন৷

প্রতিবেদনটি ডাউনলোড করুন

আপনি প্রতিটি রিপোর্ট ফাইলের URL-এ সরাসরি আঘাত করে, অথবা রিপোর্ট আইডি এবং ফাইল নম্বর (0 ইন্ডেক্সড) সহ Reports.getFile() এ কল করে প্রতিবেদনটি ডাউনলোড করতে পারেন। Search Ads 360 একটি UTF-8 এনকোড করা ফাইলে রিপোর্ট প্রদান করে।

এখানে Reports.getFile() অনুরোধের উদাহরণ রয়েছে:

JSON

GET https://www.googleapis.com/doubleclicksearch/v2/reports/MTMyNDM1NDYK/files/0?alt=media
এবং
GET https://www.googleapis.com/doubleclicksearch/v2/reports/MTMyNDM1NDYK/files/1?alt=media
          

জাভা

/**
 * Downloads the shards of a completed report to the given local directory.
 * Files are named CampaignReport0.csv, CampaignReport1.csv, and so on.
 */
private static void downloadFiles(
    Doubleclicksearch service,
    Report report,
    String localPath) throws IOException {
  for (int i = 0; i < report.getFiles().size(); i++) {
    FileOutputStream outputStream =
        new FileOutputStream(new File(localPath, "CampaignReport" + i));
    service.reports().getFile(report.getId(), i).executeAndDownloadTo(outputStream);
    outputStream.close();
  }
}

.নেট

using api = Google.Apis.Doubleclicksearch.v2;

/// <summary>
/// Downloads the shards of a completed report to the given local directory.
/// Files are named CampaignReport0.csv, CampaignReport1.csv, and so on.
/// </summary>
/// <param name="service">Search Ads 360 API service.</param>
/// <param name="report">Report ID to download.</param>
/// <param name="localPath">Path of the directory to place downloaded files.</param>
private static void DownloadFiles(
    api.DoubleclicksearchService service,
    api.Data.Report report,
    string localPath)
{
    Directory.CreateDirectory(localPath);
    for (int i = 0; i < report.Files.Count; ++i)
    {
        string fileName = Path.Combine(
            localPath,
            string.Format("CampaignReport{0}.csv", i));
        Console.WriteLine("Downloading shard {0} to {1}", i, fileName);
        using (Stream dst = File.OpenWrite(fileName))
        {
            service.Reports.GetFile(report.Id, i).Download(dst);
        }
    }
}

পাইথন

def download_files(service, report_id, report_fragment):
  """Generate and print sample report.

  Args:
    service: An authorized Doubleclicksearch service.
    report_id: The ID DS has assigned to a report.
    report_fragment: The 0-based index of the file fragment from the files array.
  """
  f = file('report-' + report_fragment + '.csv', 'w')
  request = service.reports().getFile_media(reportId=report_id, reportFragment=report_fragment)
  f.write(request.execute().decode('utf-8'))
  f.close()

উদাহরণ রিপোর্ট

এখানে একটি CSV রিপোর্টের উদাহরণ। প্রতিটি রিপোর্ট ফাইল খণ্ডের নিজস্ব শিরোনাম সারি আছে। এই বিন্যাস সম্পর্কে বিস্তারিত জানার জন্য, RFC 4180 দেখুন।

keywordText,campaignId,landingPageUrl,day,revenue,visits last month,my revenue
google,71700000002104742,http://www.google.com,2012-05-01,10.2,5,20
google,71700000002104742,http://www.google.com,2012-05-02,11,10,60.23
      

আইডি ম্যাপিং ফাইল ডাউনলোড করুন

আপনি আগের Search Ads 360 এবং নতুন Search Ads 360-এর মধ্যে আইডি ম্যাপিং আছে এমন ফাইলটি ডাউনলোড করতে পারেন। অনুরোধ করা বিজ্ঞাপনদাতার জন্য, ফাইলটিতে সমস্ত চাইল্ড এন্টিটি (যেমন ইঞ্জিন অ্যাকাউন্ট, প্রচারাভিযান, বিজ্ঞাপন গোষ্ঠী ইত্যাদি) রয়েছে যা উভয়েই বিদ্যমান। পূর্ববর্তী অনুসন্ধান বিজ্ঞাপন 360 এবং নতুন অনুসন্ধান বিজ্ঞাপন 360৷

পাইথন

def download_mapping_file(service, file_name, agency_id, advertiser_id):
    """Generate and save mapping file to a csv.

    Args:
      service: An authorized Doubleclicksearch service.
      file_name: Filename to write the ID mapping file.
      agency_id: DS ID of the agency.
      advertiser_id: DS ID of the advertiser.
    """
    request = service.reports().getIdMappingFile_media(agencyId=agency_id,
        advertiserId=advertiser_id)

    response = request.execute()
    response = response.decode('utf-8')

    f = open(file_name + '.csv', 'w')
    f.write(response)
    f.close()