แชร์ผ่าน


โปรแกรมจัดการบริการการรายงาน

โฆษณา Bing .NET, Java และ Python SDK มีชั้นเรียนเพื่อเร่งประสิทธิภาพการทํางานสําหรับการดาวน์โหลดบันทึกรายงานประสิทธิภาพการทํางาน ตัวอย่างเช่น ReportingServiceManager จะส่งคําขอดาวน์โหลดของคุณไปยัง บริการการรายงาน ทําการสํารวจบริการจนกว่าจะเสร็จสมบูรณ์ และดาวน์โหลดไฟล์ไปยังไดเรกทอรีภายในเครื่องของคุณ นอกจากนี้ ReportingServiceManager ยังจัดการเขตข้อมูลส่วนหัวของคําขอทั่วไปสําหรับคุณ โดยอนุญาตให้ระบุคุณสมบัติการรับรองความถูกต้อง,CustomerId, AccountId และ DeveloperToken ในวัตถุ AuthorizationData หนึ่งครั้งสําหรับแต่ละบริการ สําหรับข้อมูลเพิ่มเติม โปรดดูการใช้ AuthorizationData และตัวอย่างรหัสคําขอรายงาน

หมายเหตุ

ReportingServiceManager จะพร้อมใช้งานเฉพาะกับ Bing Ads .NET, Java และ Python SDKs เท่านั้น ไม่ว่าคุณจะใช้ SDK หรือไม่คุณสามารถใช้ บริการการรายงาน ได้โดยตรง สําหรับข้อมูลเพิ่มเติม ดูร้องขอและดาวน์โหลดรายงาน

ตัวอ่านไฟล์รายงาน

คุณไม่จําเป็นต้องใช้ตัวแยกวิเคราะห์ไฟล์ของคุณเองเพื่ออ่านไฟล์รายงาน คุณสามารถใช้วัตถุ ReportFileReader เพื่ออ่านไฟล์ CSV ลงในคอนเทนเนอร์ รายงาน ได้

หมายเหตุ

ReportingServiceManager ใช้ ReportFileReader ในพื้นหลังเมื่อคุณดาวน์โหลดเอนทิตีแทนไฟล์ ไฟล์ชั่วคราวถูกใช้ในพื้นหลัง สําหรับรายละเอียดเพิ่มเติม ดูไดเรกทอรีการทํางานและ ReportingServiceManager

ลองใช้ไฟล์ CSV ต่อไปนี้เป็นตัวอย่าง ตัวอย่างเช่น สมมติว่าคุณต้องการอ่านรายงานต่อไปนี้จากไฟล์

"Report Name: My Keyword Performance Report"
"Report Time: 2/7/2020"
"Time Zone: (GMT-08:00) Pacific Time (US & Canada); Tijuana"
"Last Completed Available Day: 2/8/2020 10:15:00 PM (GMT)"
"Last Completed Available Hour: 2/8/2020 10:15:00 PM (GMT)"
"Report Aggregation: Summary"
"Report Filter: "
"Potential Incomplete Data: true"
"Rows: 5"

"AccountId","CampaignId","Keyword","KeywordId","DeviceType","Clicks"
"YourAccountId","YourCampaignId","red shoes","123","Computer","35"
"YourAccountId","YourCampaignId","red shoes","123","Smartphone","50"
"YourAccountId","YourCampaignId","shoes delivered","234","Computer","1"
"YourAccountId","YourCampaignId","shoe sale","345","Computer","80"
"YourAccountId","YourCampaignId","shoe sale","345","Smartphone","5"

"@2020 Microsoft Corporation. All rights reserved. "

เพียงแค่ระบุ ReportFileReader ด้วยเส้นทางไฟล์และชื่อไฟล์ จากนั้นปิดไฟล์เมื่อคุณอ่านเสร็จแล้ว

ReportFileReader reportFileReader = new ReportFileReader(
    ResultFileName,
    ReportFormat.Csv
);
Report report = reportFileReader.GetReport();
IEnumerable<IReportRecord> reportRecordIterable = reportContainer.GetReportRecords();
report.Dispose();
ReportFileReader reportFileReader = new ReportFileReader(
    ResultFileName,
    ReportFormat.CSV
);
Report report = reportFileReader.getReport();
Iterable<ReportRecord> reportRecords = report.getReportRecords();
report.close();
report_file_reader = ReportFileReader(
    file_path=result_file_name, 
    format='Csv'
)
report_container=report_file_reader.get_report()
report_record_iterable=report_container.report_records
report_container.close()

คอนเทนเนอร์รายงาน In-Memory

รายงานเป็นคอนเทนเนอร์ในหน่วยความจําที่นามธรรมเนื้อหาของไฟล์รายงานที่ดาวน์โหลด รวมถึงเมตาดาต้าส่วนหัว ชื่อคอลัมน์ และเรกคอร์ดรายงาน ด้วยการอัปเดตเหล่านี้คุณสามารถมุ่งเน้นไปที่ข้อกําหนดทางธุรกิจของแอปพลิเคชันของคุณแทนที่จะแยกวิเคราะห์ไฟล์รายงาน

คุณสามารถเข้าถึงคอนเทนเนอร์รายงานในหน่วยความจําผ่าน ReportingServiceManager ได้โดยการส่งคําขอดาวน์โหลดใหม่ หรือโดยใช้ ReportFileReader เพื่ออ่านจากไฟล์รายงานที่คุณดาวน์โหลดไว้แล้ว

ตัวอย่างเช่น คุณสามารถรับวัตถุรายงานได้โดยการส่งคําขอดาวน์โหลดใหม่ผ่าน ReportingServiceManager แม้ว่าในกรณีนี้คุณจะไม่สามารถทํางานกับไฟล์ได้โดยตรง แต่ภายใต้ครอบคลุมคําขอจะถูกส่งไปยังบริการการรายงานและไฟล์รายงานจะถูกดาวน์โหลดไปยังไดเรกทอรีภายในเครื่อง พารามิเตอร์การดาวน์โหลดการรายงานประกอบด้วยชนิดรายงาน ขอบเขต ช่วงเวลา และเส้นทางไฟล์ดาวน์โหลดภายในเครื่อง

// The ReportRequest is a ReportRequest object defined by the Reporting API.
var reportingDownloadParameters = new ReportingDownloadParameters
{
    ReportRequest = reportRequest,
    ResultFileDirectory = FileDirectory,
    ResultFileName = ResultFileName,
    OverwriteResultFile = true,
};

Report reportContainer = await ReportingServiceManager.DownloadReportAsync(
    reportingDownloadParameters,
    CancellationToken.None
);
// The ReportRequest is a ReportRequest object defined by the Reporting API.
ReportingDownloadParameters reportingDownloadParameters = new ReportingDownloadParameters();
reportingDownloadParameters.setReportRequest(reportRequest);
reportingDownloadParameters.setResultFileDirectory(new File(FileDirectory));
reportingDownloadParameters.setResultFileName(ResultFileName);
reportingDownloadParameters.setOverwriteResultFile(true);

Report reportContainer = ReportingServiceManager.downloadReportAsync(
    reportingDownloadParameters, 
    null
).get(); 
# The report_request is a ReportRequest object defined by the Reporting API.
reporting_download_parameters = ReportingDownloadParameters(
    report_request=report_request,
    result_file_directory = FILE_DIRECTORY, 
    result_file_name = DOWNLOAD_FILE_NAME, 
    overwrite_result_file = True
)

report_container = reporting_service_manager.download_report(
    reporting_download_parameters=reporting_download_parameters
)

มิฉะนั้น หากคุณมีไฟล์รายงานที่ดาวน์โหลดผ่าน API อยู่แล้ว คุณสามารถรับวัตถุรายงานผ่าน ReportFileReader ได้

ReportFileReader reader = new ReportFileReader(
    "c:\\reports\\result.csv",
    ReportFormat.Csv
);
Report reportContainer = reader.GetReport();
ReportFileReader reader = new ReportFileReader(
    reportingDownloadParameters.getResultFileDirectory() + "\\" + reportingDownloadParameters.getResultFileName(), 
    reportingDownloadParameters.getReportRequest().getFormat()
);
Report reportContainer = reader.getReport();
report_file_reader = ReportFileReader(
    file_path=reporting_download_parameters.result_file_directory + reporting_download_parameters.result_file_name, 
    format=reporting_download_parameters.report_request.Format
)
report_container = report_file_reader.get_report()

เมื่อคุณมีวัตถุรายงานผ่านเวิร์กโฟลว์ด้านบนคุณสามารถเข้าถึงเรกคอร์ดเมตาดาต้าและรายงานได้ หากไม่มีข้อมูลรายงานสําหรับการส่งเสริมการขายและวันที่ที่คุณส่ง ผลการดาวน์โหลดจะเป็น Null หรือค่าว่าง

// Output the report metadata

long recordCount = reportContainer.ReportRecordCount;
Console.WriteLine(string.Format("ReportName: {0}", reportContainer.ReportName));
Console.WriteLine(string.Format("ReportTimeStart: {0}", reportContainer.ReportTimeStart));
Console.WriteLine(string.Format("ReportTimeEnd: {0}", reportContainer.ReportTimeEnd));
Console.WriteLine(string.Format("LastCompletedAvailableDate: {0}", reportContainer.LastCompletedAvailableDate.ToString()));
Console.WriteLine(string.Format("ReportAggregation: {0}", reportContainer.ReportAggregation.ToString()));
Console.WriteLine(string.Format("ReportColumns: {0}", string.Join("; ", reportContainer.ReportColumns)));
Console.WriteLine(string.Format("ReportRecordCount: {0}", recordCount));

// Analyze and output performance statistics

IEnumerable<IReportRecord> reportRecordIterable = reportContainer.GetReportRecords();
            
int totalImpressions = 0;
int totalClicks = 0;
HashSet<string> distinctDevices = new HashSet<string>();
HashSet<string> distinctNetworks = new HashSet<string>();
foreach (IReportRecord record in reportContainer.GetReportRecords())
{
    totalImpressions += record.GetIntegerValue("Impressions");
    totalClicks += record.GetIntegerValue("Clicks");
    distinctDevices.Add(record.GetStringValue("DeviceType"));
    distinctNetworks.Add(record.GetStringValue("Network"));
}

Console.WriteLine(string.Format("Total Impressions: {0}", totalImpressions));
Console.WriteLine(string.Format("Total Clicks: {0}", totalClicks));
Console.WriteLine(string.Format("Average Impressions: {0}", totalImpressions * 1.0 / recordCount));
Console.WriteLine(string.Format("Average Clicks: {0}", totalClicks * 1.0 / recordCount));
Console.WriteLine(string.Format("Distinct Devices: {0}", string.Join("; ", distinctDevices)));
Console.WriteLine(string.Format("Distinct Networks: {0}", string.Join("; ", distinctNetworks)));

// Be sure to close the report before you attempt to clean up files within the working directory.

reportContainer.Dispose();
// Output the reportRequest metadata

java.lang.Long recordCount = reportContainer.getReportRecordCount();
outputStatusMessage(String.format("ReportName: %s", reportContainer.getReportName()));
outputStatusMessage(String.format("ReportTimeStart: %s", reportContainer.getReportTimeStart()));
outputStatusMessage(String.format("ReportTimeEnd: %s", reportContainer.getReportTimeEnd()));
outputStatusMessage(String.format("LastCompletedAvailableDate: %s", reportContainer.getLastCompletedAvailableDate().toString()));
outputStatusMessage(String.format("ReportAggregation: %s", enumCaseToPascalCase(reportContainer.getReportAggregation().toString())));
outputStatusMessage(String.format("ReportColumns: %s", String.join("; ", reportContainer.getReportColumns())));
outputStatusMessage(String.format("ReportRecordCount: %s", recordCount));

// Analyze and output performance statistics

if(Arrays.asList(reportContainer.getReportColumns()).contains("Impressions")){
    Iterable<ReportRecord> reportRecordIterable = reportContainer.getReportRecords();

    int totalImpressions = 0;
    int totalClicks = 0;
    HashSet<String> distinctDevices = new HashSet<>();
    HashSet<String> distinctNetworks = new HashSet<>();
    for (ReportRecord record : reportRecordIterable)
    {
        totalImpressions += record.getIntegerValue("Impressions");
        totalClicks += record.getIntegerValue("Clicks");
        distinctDevices.add(record.getStringValue("DeviceType"));
        distinctNetworks.add(record.getStringValue("Network"));
    }

    outputStatusMessage(String.format("Total Impressions: %s", totalImpressions));
    outputStatusMessage(String.format("Total Clicks: %s", totalClicks));
    outputStatusMessage(String.format("Average Impressions: %s", totalImpressions * 1.0 / recordCount));
    outputStatusMessage(String.format("Average Clicks: %s", totalClicks * 1.0 / recordCount));
    outputStatusMessage(String.format("Distinct Devices: %s", String.join("; ", distinctDevices)));
    outputStatusMessage(String.format("Distinct Networks: %s", String.join("; ", distinctNetworks)));
}       

// Be sure to close the reportRequest before you attempt to clean up files within the working directory.

reportContainer.close();
# Output the reportRequest metadata
record_count = report_container.record_count
output_status_message("ReportName: {0}".format(report_container.report_name))
output_status_message("ReportTimeStart: {0}".format(report_container.report_time_start))
output_status_message("ReportTimeEnd: {0}".format(report_container.report_time_end))
output_status_message("LastCompletedAvailableDate: {0}".format(report_container.last_completed_available_date))
output_status_message("ReportAggregation: {0}".format(report_container.report_aggregation))
output_status_message("ReportColumns: {0}".format("; ".join(str(column) for column in report_container.report_columns)))
output_status_message("ReportRecordCount: {0}".format(record_count))

#Analyze and output performance statistics

if "Impressions" in report_container.report_columns and \
    "Clicks" in report_container.report_columns and \
    "DeviceType" in report_container.report_columns and \
    "Network" in report_container.report_columns:

    report_record_iterable = report_container.report_records

    total_impressions = 0
    total_clicks = 0
    distinct_devices = set()
    distinct_networks = set()
    for record in report_record_iterable:
        total_impressions += record.int_value("Impressions")
        total_clicks += record.int_value("Clicks")
        distinct_devices.add(record.value("DeviceType"))
        distinct_networks.add(record.value("Network"))

    output_status_message("Total Impressions: {0}".format(total_impressions))
    output_status_message("Total Clicks: {0}".format(total_clicks))
    output_status_message("Average Impressions: {0}".format(total_impressions * 1.0 / record_count))
    output_status_message("Average Clicks: {0}".format(total_clicks * 1.0 / record_count))
    output_status_message("Distinct Devices: {0}".format("; ".join(str(device) for device in distinct_devices)))
    output_status_message("Distinct Networks: {0}".format("; ".join(str(network) for network in distinct_networks)))

#Be sure to close the report.

report_container.close()

ดาวน์โหลด

ReportingServiceManager สนับสนุนเวิร์กโฟลว์การดาวน์โหลดรายงานที่ยืดหยุ่น

  • คุณสามารถสร้างคําขอดาวน์โหลดและ ReportingServiceManager จะส่งคําขอดาวน์โหลดของคุณไปยังบริการการรายงาน ทําการสํารวจบริการจนกว่าจะเสร็จสมบูรณ์ และดาวน์โหลดไฟล์ไปยังไดเรกทอรีภายในเครื่องของคุณ ตัวอย่างเช่น ดูพื้นหลังเสร็จสมบูรณ์ด้วย ReportingServiceManager

  • คุณสามารถส่งคําขอดาวน์โหลดและทําการสํารวจจนกว่าไฟล์ผลลัพธ์จะพร้อมสําหรับการดาวน์โหลด ตัวอย่างเช่น ดูส่งและดาวน์โหลดด้วย ReportingServiceManager

  • หากด้วยเหตุผลใดก็ตามคุณต้องดําเนินการต่อจากสถานะแอปพลิเคชันก่อนหน้า คุณสามารถใช้ตัวระบุคําขอดาวน์โหลดที่มีอยู่และใช้เพื่อดาวน์โหลดไฟล์ผลลัพธ์ได้ ตัวอย่างเช่น ดูดาวน์โหลดผลลัพธ์ด้วย ReportingServiceManager

การทํางานแบบเบื้องหลังด้วย ReportingServiceManager

คุณสามารถสร้างคําขอดาวน์โหลดและ ReportingServiceManager จะส่งคําขอดาวน์โหลดของคุณไปยังบริการการรายงาน ทําการสํารวจบริการจนกว่าจะเสร็จสมบูรณ์ และดาวน์โหลดไฟล์ไปยังไดเรกทอรีภายในเครื่องของคุณ

public async Task RunAsync(AuthorizationData authorizationData)
{
    ReportingServiceManager reportingServiceManager = new ReportingServiceManager(authorizationData);

    var reportRequest = GetCampaignPerformanceReportRequest(authorizationData.AccountId);

    var reportingDownloadParameters = new ReportingDownloadParameters
    {
        ReportRequest = reportRequest,
        ResultFileDirectory = FileDirectory,
        ResultFileName = ResultFileName,
        OverwriteResultFile = true,
    };

    // Sets the time interval in milliseconds between two status polling attempts. The default value is 5000 (5 seconds).
    reportingServiceManager.StatusPollIntervalInMilliseconds = 5000;
    // Sets the timeout of the HttpClient download operation. The default value is 100000 (100s).
    reportingServiceManager.DownloadHttpTimeout = new TimeSpan(0, 0, 100);

    // You may optionally cancel the DownloadFileAsync operation after a specified time interval. 
    // Pass this object to the DownloadFileAsync operation or specify CancellationToken.None. 
    var tokenSource = new CancellationTokenSource();
    tokenSource.CancelAfter(3600000);

    // The ReportingServiceManager will submit your download request to the Reporting service, 
    // poll the service until completed, and download the file to your local directory.

    var resultFilePath = await reportingServiceManager.DownloadFileAsync(
        parameters: reportingDownloadParameters, 
        cancellationToken: tokenSource.Token
    );
    Console.WriteLine(string.Format("Download result file: {0}\n", resultFilePath));
}
ReportingServiceManager reportingServiceManager = new ReportingServiceManager(authorizationData);

ReportRequest reportRequest = getCampaignPerformanceReportRequest();

ReportingDownloadParameters reportingDownloadParameters = new ReportingDownloadParameters();
reportingDownloadParameters.setReportRequest(reportRequest);
reportingDownloadParameters.setResultFileDirectory(new File(FileDirectory));
reportingDownloadParameters.setResultFileName(ResultFileName);
reportingDownloadParameters.setOverwriteResultFile(true);

// Sets the time interval in milliseconds between two status polling attempts. The default value is 5000 (5 seconds).
reportingServiceManager.setStatusPollIntervalInMilliseconds(5000);
// Sets the timeout of the HttpClient download operation. The default value is 100000 (100s).
reportingServiceManager.setDownloadHttpTimeoutInMilliseconds(100000);

// The ReportingServiceManager will submit your download request to the Reporting service, 
// poll the service until completed, and download the file to your local directory. 
// You may optionally cancel the downloadFileAsync operation after a specified time interval.
File resultFile = reportingServiceManager.downloadFileAsync(
    reportingDownloadParameters, 
    null
).get(3600000, TimeUnit.MILLISECONDS);

System.out.println(String.format("Download result file: %s\n", resultFile.getName()));
reporting_service_manager=ReportingServiceManager(
    authorization_data=authorization_data, 
    # Sets the time interval in milliseconds between two status polling attempts. 
    # The default value is 5000 (5 seconds).
    poll_interval_in_milliseconds=5000, 
    environment=ENVIRONMENT,
)

report_request=get_keyword_report_request()

reporting_download_parameters = ReportingDownloadParameters(
    report_request=report_request,
    result_file_directory = FILE_DIRECTORY, 
    result_file_name = DOWNLOAD_FILE_NAME, 
    overwrite_result_file = True, # Set this value true if you want to overwrite the same file.
    timeout_in_milliseconds=3600000 # You may optionally cancel the download after a specified time interval.
)

# The ReportingServiceManager will submit your download request to the Reporting service, 
# poll the service until completed, and download the file to your local directory.
result_file_path = reporting_service_manager.download_file(
    reporting_download_parameters=reporting_download_parameters
)
print("Download result file: {0}\n".format(result_file_path))

ส่งและดาวน์โหลดด้วย ReportingServiceManager

ส่งคําขอดาวน์โหลด จากนั้นใช้ผลลัพธ์ ReportingDownloadOperation เพื่อติดตามสถานะด้วยตัวคุณเองโดยใช้ GetStatusAsync

public async Task RunAsync(AuthorizationData authorizationData)
{
    ReportingService = new ReportingServiceManager(authorizationData);

    var reportRequest = GetCampaignPerformanceReportRequest(authorizationData.AccountId);

    var reportingDownloadOperation = await ReportingService.SubmitDownloadAsync(reportRequest);

    // You may optionally cancel the TrackAsync operation after a specified time interval. 
    var tokenSource = new CancellationTokenSource();
    tokenSource.CancelAfter(3600000);

    var reportingDownloadOperation = await ReportingService.SubmitDownloadAsync(reportRequest);

    ReportingOperationStatus reportingOperationStatus = await reportingDownloadOperation.TrackAsync(tokenSource.Token);

    var resultFilePath = await reportingDownloadOperation.DownloadResultFileAsync(
        FileDirectory,
        ResultFileName,
        decompress: true,
        overwrite: true  // Set this value true if you want to overwrite the same file.
    );   

    Console.WriteLine(string.Format("Download result file: {0}\n", resultFilePath));
}
ReportingServiceManager = new ReportingServiceManager(authorizationData);

ReportRequest reportRequest = getCampaignPerformanceReportRequest();

ReportingDownloadOperation reportingDownloadOperation = ReportingServiceManager.submitDownloadAsync(
    reportRequest,
    null
).get();

// You may optionally cancel the trackAsync operation after a specified time interval.
ReportingOperationStatus reportingOperationStatus = reportingDownloadOperation.trackAsync(
    null
).get(3600000, TimeUnit.MILLISECONDS);

File resultFile = reportingDownloadOperation.downloadResultFileAsync(
    new File(FileDirectory),
    ResultFileName,
    true, // Set this value to true if you want to decompress the ZIP file.
    true,  // Set this value true if you want to overwrite the named file.
    null
).get();

System.out.println(String.format("Download result file: %s\n", resultFile.getName()));
reporting_service_manager=ReportingServiceManager(
    authorization_data=authorization_data, 
    poll_interval_in_milliseconds=5000, 
    environment=ENVIRONMENT,
)

# In addition to ReportingServiceManager, you will need a reporting ServiceClient 
# to build the ReportRequest.

reporting_service=ServiceClient(
    'ReportingService', 
    version=13,
    authorization_data=authorization_data, 
    environment=ENVIRONMENT,
)

report_request=get_keyword_report_request()

reporting_download_operation = reporting_service_manager.submit_download(report_request)

# You may optionally cancel the track() operation after a specified time interval.
reporting_operation_status = reporting_download_operation.track(timeout_in_milliseconds=3600000)
    
result_file_path = reporting_download_operation.download_result_file(
    result_file_directory = FILE_DIRECTORY, 
    result_file_name = DOWNLOAD_FILE_NAME, 
    decompress = True, 
    overwrite = True,  # Set this value true if you want to overwrite the same file.
    timeout_in_milliseconds=3600000 # You may optionally cancel the download after a specified time interval.
)
    
print("Download result file: {0}\n".format(result_file_path))

ดาวน์โหลดผลลัพธ์ด้วย ReportingServiceManager

หากด้วยเหตุผลใดก็ตามคุณต้องดําเนินการต่อจากสถานะแอปพลิเคชันก่อนหน้า คุณสามารถใช้ตัวระบุคําขอดาวน์โหลดที่มีอยู่และใช้เพื่อดาวน์โหลดไฟล์ผลลัพธ์ได้ ใช้ TrackAsync เพื่อระบุว่าแอปพลิเคชันควรรอเพื่อให้แน่ใจว่าสถานะการดาวน์โหลดเสร็จสมบูรณ์แล้ว

public async Task RunAsync(AuthorizationData authorizationData)
{
    ReportingService = new ReportingServiceManager(authorizationData);

    // You may optionally cancel the TrackAsync operation after a specified time interval. 
    var tokenSource = new CancellationTokenSource();
    tokenSource.CancelAfter(3600000);

    var reportingDownloadOperation = new ReportingDownloadOperation(RequestIdGoesHere, authorizationData);

    // Use TrackAsync to indicate that the application should wait to ensure that 
    // the download status is completed.
    var reportingOperationStatus = await reportingDownloadOperation.TrackAsync(tokenSource.Token);

    var resultFilePath = await reportingDownloadOperation.DownloadResultFileAsync(
        FileDirectory,
        ResultFileName,
        decompress: true,
        overwrite: true   // Set this value true if you want to overwrite the same file.
    );   

    Console.WriteLine(string.Format("Download result file: {0}", resultFilePath));
    Console.WriteLine(string.Format("Status: {0}", reportingOperationStatus.Status));
    Console.WriteLine(string.Format("TrackingId: {0}\n", reportingOperationStatus.TrackingId));
}
java.lang.String requestId = RequestIdGoesHere;

ReportingDownloadOperation reportingDownloadOperation = new ReportingDownloadOperation(
    requestId, 
    authorizationData
);

reportingDownloadOperation.setStatusPollIntervalInMilliseconds(5000);

// You can use trackAsync to poll until complete as shown here, 
// or use custom polling logic with getStatusAsync.

// You may optionally cancel the trackAsync operation after a specified time interval.
ReportingOperationStatus reportingOperationStatus = reportingDownloadOperation.trackAsync(
    null
).get(3600000, TimeUnit.MILLISECONDS);

File resultFile = reportingDownloadOperation.downloadResultFileAsync(
    new File(FileDirectory),
    ResultFileName,
    true, // Set this value to true if you want to decompress the ZIP file
    true,  // Set this value true if you want to overwrite the named file.
    null
).get();

System.out.println(String.format("Download result file: %s", resultFile.getName()));
System.out.println(String.format("Status: %s", reportingOperationStatus.getStatus()));
System.out.println(String.format("TrackingId: %s\n", reportingOperationStatus.getTrackingId()));
reporting_download_operation = ReportingDownloadOperation(
    request_id = RequestIdGoesHere, 
    authorization_data=authorization_data, 
    poll_interval_in_milliseconds=5000, 
    environment=ENVIRONMENT,
)

# Use track() to indicate that the application should wait to ensure that 
# the download status is completed.
# You may optionally cancel the track() operation after a specified time interval.
reporting_operation_status = reporting_download_operation.track(timeout_in_milliseconds=3600000)
    
result_file_path = reporting_download_operation.download_result_file(
    result_file_directory = FILE_DIRECTORY, 
    result_file_name = DOWNLOAD_FILE_NAME, 
    decompress = True, 
    overwrite = True,  # Set this value true if you want to overwrite the same file.
    timeout_in_milliseconds=3600000 # You may optionally cancel the download after a specified time interval.
) 

print("Download result file: {0}".format(result_file_path))
print("Status: {0}\n".format(reporting_operation_status.status))

Poll และลองใหม่

ReportingServiceManager ทําการสํารวจโดยอัตโนมัติในช่วงเวลา 1000 มิลลิวินาทีสําหรับความพยายามห้าครั้งแรก และลักษณะการทํางานนั้นไม่สามารถกําหนดค่าได้ คุณสมบัติ StatusPollIntervalInMilliseconds จะกําหนดช่วงเวลาระหว่างความพยายามในการโพลล์แต่ละครั้งหลังจากความพยายามห้าครั้งแรก ตัวอย่างเช่น โปรดดู การทําให้พื้นหลังสมบูรณ์ ด้านบน ค่าเริ่มต้นคือ 5000 ดังนั้นถ้าคุณไม่ได้ตั้งค่านี้ ReportingServiceManager จะทําการสํารวจในลําดับต่อไปนี้: 1, 2, 3, 4, 5, 10, 15, 20 และอื่น ๆ ถ้าคุณตั้งค่านี้เป็น 10000 ReportingServiceManager จะสํารวจในลําดับต่อไปนี้: 1, 2, 3, 4, 5, 15, 25, 35 และอื่น ๆ ช่วงการสํารวจต่ําสุดคือ 1000 และถ้าคุณระบุค่าน้อยกว่า 1000 ข้อยกเว้นจะแสดงขึ้นมา

ReportingServiceManager จะลองดาวน์โหลดและการโพลล์ใหม่โดยอัตโนมัติจนถึงระยะเวลาการหมดเวลาสูงสุดที่คุณระบุ คุณสามารถตั้งค่าระยะเวลาการหมดเวลาการลองใหม่สูงสุดได้ ถ้าไม่มีการระบุการหมดเวลา ReportingServiceManager จะลองใหม่ต่อไปจนกว่าเซิร์ฟเวอร์จะส่งกลับข้อผิดพลาดการหมดเวลาหรือข้อผิดพลาดภายใน แยกกัน ถ้าคุณกําลังดาวน์โหลดไฟล์ขนาดใหญ่ คุณควรพิจารณาการตั้งค่าคุณสมบัติ DownloadHttpTimeout

ไดเรกทอรีการทํางานและ ReportingServiceManager

ด้วย Bing Ads .NET และ Java SDKs คุณสามารถตั้งค่าไดเรกทอรีการทํางานที่ ReportingServiceManager ควรจัดเก็บไฟล์รายงานชั่วคราวได้ ตัวอย่างเช่น เมื่อคุณดาวน์โหลดคอนเทนเนอร์รายงาน แม้ว่าคุณจะทํางานกับวัตถุรายงานไฟล์รายงานจะถูกดาวน์โหลดไปยังไดเรกทอรีการทํางานเท่านั้น ไดเรกทอรีชั่วคราวของระบบจะถูกใช้ถ้าไม่มีการระบุไดเรกทอรีการทํางานอื่น

ถ้าคุณกําลังใช้บริการที่เป็นโฮสต์ เช่น Microsoft Azure คุณจะต้องการให้แน่ใจว่าคุณไม่เกินขีดจํากัดไดเรกทอรีชั่วคราว อาจมีเหตุผลอื่นในการใช้ไดเรกทอรีการทํางานแบบกําหนดเอง คุณสามารถระบุไดเรกทอรีการทํางานที่แตกต่างกันสําหรับแต่ละอินสแตนซ์ ReportingServiceManager ได้โดยการตั้งค่าคุณสมบัติ WorkingDirectory นอกจากนี้คุณยังรับผิดชอบสําหรับการสร้างและลบไดเรกทอรีใด ๆ

สิ่งสำคัญ

หลังจากที่คุณได้ดําเนินการซ้ําผ่านเรกคอร์ดรายงานแล้ว คุณสามารถล้างข้อมูลไฟล์จากไดเรกทอรีการทํางานได้ เมธอด CleanupTempFiles จะลบไฟล์ทั้งหมด (แต่ไม่ใช่ไดเรกทอรีย่อยใดๆ) ภายในไดเรกทอรีการทํางาน ไม่ว่าจะสร้างไฟล์โดยอินสแตนซ์ ReportingServiceManager ปัจจุบันหรือไม่

ReportingServiceManager reportingServiceManager = new ReportingServiceManager(
    authorizationData: authorizationData, 
    apiEnvironment: environment
);

var reportRequest = GetReportRequest(authorizationData.AccountId);

var reportingDownloadParameters = new ReportingDownloadParameters
{
    ReportRequest = reportRequest,
    ResultFileDirectory = FileDirectory,
    ResultFileName = ResultFileName,
    OverwriteResultFile = true,
};

// The system temp directory will be used if another working directory is not specified. If you are 
// using a hosted service such as Microsoft Azure you'll want to ensure you do not exceed the file or directory limits. 
// You can specify a different working directory for each ReportingServiceManager instance.

reportingServiceManager.WorkingDirectory = FileDirectory;

// You can get a Report object by submitting a new download request via ReportingServiceManager. 
// Although in this case you won't work directly with the file, under the covers a request is 
// submitted to the Reporting service and the report file is downloaded to a local directory. 

Report reportContainer = await reportingServiceManager.DownloadReportAsync(
    parameters: reportingDownloadParameters,
    cancellationToken: CancellationToken.None
);

IEnumerable<IReportRecord> reportRecordIterable = reportContainer.GetReportRecords();

// Be sure to close the report before you attempt to clean up files within the working directory.

reportContainer.Dispose();

// The CleanupTempFiles method removes all files (but not sub-directories) within the working directory, 
// whether or not the files were created by this ReportingServiceManager instance. 

reportingServiceManager.CleanupTempFiles();
ReportingServiceManager reportingServiceManager = new ReportingServiceManager(authorizationData, API_ENVIRONMENT);
reportingServiceManager.setStatusPollIntervalInMilliseconds(5000);

ReportRequest reportRequest = getReportRequest(authorizationData.getAccountId());

ReportingDownloadParameters reportingDownloadParameters = new ReportingDownloadParameters();
reportingDownloadParameters.setReportRequest(reportRequest);
reportingDownloadParameters.setResultFileDirectory(new File(FileDirectory));
reportingDownloadParameters.setResultFileName(ResultFileName);
reportingDownloadParameters.setOverwriteResultFile(true);

// The system temp directory will be used if another working directory is not specified. If you are 
// using a hosted service such as Microsoft Azure you'll want to ensure you do not exceed the file or directory limits. 
// You can specify a different working directory for each ReportingServiceManager instance.

reportingServiceManager.setWorkingDirectory(new File(FileDirectory));

// You can get a Report object by submitting a new download request via ReportingServiceManager. 
// Although in this case you won't work directly with the file, under the covers a request is 
// submitted to the Reporting service and the report file is downloaded to a local directory. 

Report reportContainer = reportingServiceManager.downloadReportAsync(
    reportingDownloadParameters, 
    null
).get(); 

java.lang.Long recordCount = reportContainer.getReportRecordCount();

// Be sure to close the reportRequest before you attempt to clean up files within the working directory.

reportContainer.close();

// The cleanupTempFiles method removes all files (but not sub-directories) within the working directory, 
// whether or not the files were created by this ReportingServiceManager instance. 

reportingServiceManager.cleanupTempFiles();

ดูเพิ่มเติม

Sandbox
ตัวอย่างรหัส API ของโฆษณา Bing
ที่อยู่ของบริการเว็บ API ของ Bing Ads