แชร์ผ่าน


ตัวจัดการบริการจํานวนมาก

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

หมายเหตุ

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

ตัวอ่านและเขียนไฟล์จํานวนมาก

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

หมายเหตุ

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

ตัวอย่างเช่น สมมติว่าคุณต้องการเขียนระเบียน โฆษณาข้อความแบบขยาย ต่อไปนี้ลงในไฟล์จํานวนมาก

Type,Status,Id,Parent Id,Campaign,Ad Group,Client Id,Modified Time,Title,Text,Text Part 2,Display Url,Destination Url,Promotion,Device Preference,Ad Format Preference,Name,App Platform,App Id,Final Url,Mobile Final Url,Tracking Template,Custom Parameter,Title Part 1,Title Part 2,Title Part 3,Path 1,Path 2
Format Version,,,,,,,,,,,,,,,6.0,,,,,,,,,,,
Expanded Text Ad,Active,,-1111,ParentCampaignNameGoesHere,AdGroupNameGoesHere,ClientIdGoesHere,,,Find New Customers & Increase Sales!,Start Advertising on Contoso Today.,,,,,False,,,,https://www.contoso.com/womenshoesale,https://mobile.contoso.com/womenshoesale,,{_promoCode}=PROMO1; {_season}=summer,Contoso,Quick & Easy Setup,Seemless Integration,seattle,shoe sale

ก่อนอื่น ให้สร้างวัตถุ BulkExpandedTextAd ดังที่แสดงด้านล่างในแผนที่เอนทิตีการจัดการกลุ่มและการจัดการแคมเปญ จากนั้นคุณสามารถเขียน BulkExpandedTextAd ไปยังไฟล์ด้วย BulkFileWriter ดังที่แสดงไว้ที่นี่

var bulkFileWriter = new BulkFileWriter(
    filePath: FileDirectory + UploadFileName
);
bulkFileWriter.WriteEntity(bulkExpandedTextAd);
bulkFileWriter.Dispose();
BulkFileWriter bulkFileWriter = new BulkFileWriter(
    new File(FileDirectory + UploadFileName)
);
bulkFileWriter.writeEntity(bulkExpandedTextAd);
bulkFileWriter.close();
bulk_file_writer=BulkFileWriter(
    file_path=FILE_DIRECTORY+UPLOAD_FILE_NAME
)
bulk_file_writer.write_entity(bulk_expanded_text_ad)
bulk_file_writer.close()

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

var bulkFileReader = new BulkFileReader(
    filePath: bulkFilePath, // Path to the Bulk file
    resultFileType: ResultFileType.Upload, // FullDownload, PartialDownload, or Upload
    fileFormat: DownloadFileType.Csv // Csv or Tsv
);
var resultEntities = bulkFileReader.ReadEntities().ToList();
var expandedTextAdResults = resultEntities.OfType<BulkExpandedTextAd>().ToList();
OutputBulkExpandedTextAds(expandedTextAdResults);
bulkFileReader.Dispose();
BulkFileReader bulkFileReader = new BulkFileReader(
    bulkFilePath, // Path to the Bulk file
    ResultFileType.UPLOAD, // FULL_DOWNLOAD, PARTIAL_DOWNLOAD, or UPLOAD
    DownloadFileType.CSV  // Csv or Tsv
);
BulkEntityIterable resultEntities = bulkFileReader.getEntities();
for (BulkEntity entity : resultEntities) {
    if (entity instanceof BulkExpandedTextAd) {
        outputBulkBulkExpandedTextAds(Arrays.asList((BulkExpandedTextAd) entity));
    }
}
resultEntities.close();
bulkFileReader.close();
def read_entities_from_bulk_file(file_path, result_file_type, file_type):
    with BulkFileReader(file_path=file_path, result_file_type=result_file_type, file_type=file_type) as reader:
        for entity in reader:
            yield entity

def main():
    result_entities=[]
    entities_generator=read_entities_from_bulk_file(
        file_path=bulk_file_path, # Path to the Bulk file
        result_file_type=ResultFileType.upload, # full_download, partial_download, or upload
        file_type='Csv'  # Csv or Tsv
    )
    for entity in entities_generator:
        result_entities.append(entity)
    for entity in download_entities:
        if isinstance(entity, BulkExpandedTextAd):
            output_bulk_expanded_text_ads([entity])

แผนผังเอนทิตีการจัดการแคมเปญและจํานวนมาก

วัตถุทั้งหมดอ่านและเขียนไปยังไฟล์จํานวนมากผ่าน BulkServiceManager, BulkFileReader, BulkFileWriter มาจากคลาสพื้นฐาน BulkEntity เช่น BulkCampaign, BulkAdGroup และ BulkExpandedTextAd ออบเจ็กต์จํานวนมากที่เป็นไปได้จะใช้ประโยชน์จากออบเจ็กต์การจัดการการส่งเสริมการขายและชุดค่า เช่น BulkExpandedTextAd ต่อไปนี้ประกอบด้วยออบเจ็กต์ API การจัดการการส่งเสริมการขาย ExpandedTextAd

var uploadEntities = new List<BulkEntity>();

// Map properties in the Bulk file to the BulkExpandedTextAd
var bulkExpandedTextAd = new BulkExpandedTextAd
{
    // 'Parent Id' column header in the Bulk file
    AdGroupId = adGroupIdKey,
    // 'Ad Group' column header in the Bulk file
    AdGroupName = "AdGroupNameGoesHere",
    // 'Campaign' column header in the Bulk file
    CampaignName = "ParentCampaignNameGoesHere",
    // 'Client Id' column header in the Bulk file
    ClientId = "ClientIdGoesHere",

    // Map properties in the Bulk file to the 
    // ExpandedTextAd object of the Campaign Management service.
    ExpandedTextAd = new ExpandedTextAd
    {
        // 'Ad Format Preference' column header in the Bulk file
        AdFormatPreference = "All",
        // 'Mobile Final Url' column header in the Bulk file
        FinalMobileUrls = new[] {
            // Each Url is delimited by a semicolon (;) in the Bulk file
            "https://mobile.contoso.com/womenshoesale"
        },
        // 'Final Url' column header in the Bulk file
        FinalUrls = new[] {
            // Each Url is delimited by a semicolon (;) in the Bulk file
            "https://www.contoso.com/womenshoesale"
        },
        // 'Id' column header in the Bulk file
        Id = null,
        // 'Path 1' column header in the Bulk file
        Path1 = "seattle",
        // 'Path 2' column header in the Bulk file
        Path2 = "shoe sale",
        // 'Status' column header in the Bulk file
        Status = AdStatus.Active,
        // 'Text' column header in the Bulk file
        Text = "Find New Customers & Increase Sales!",
        // 'Text Part 2' column header in the Bulk file
        TextPart2 = "Start Advertising on Contoso Today.",
        // 'Title Part 1' column header in the Bulk file
        TitlePart1 = "Contoso",
        // 'Title Part 2' column header in the Bulk file
        TitlePart2 = "Quick & Easy Setup",
        // 'Title Part 3' column header in the Bulk file
        TitlePart3 = "Seemless Integration",
        // 'Tracking Template' column header in the Bulk file
        TrackingUrlTemplate = null,
        // 'Custom Parameter' column header in the Bulk file
        UrlCustomParameters = new CustomParameters
        {
            // Each custom parameter is delimited by a semicolon (;) in the Bulk file
            Parameters = new[] {
                new CustomParameter(){
                    Key = "promoCode",
                    Value = "PROMO1"
                },
                new CustomParameter(){
                    Key = "season",
                    Value = "summer"
                },
            }
        },
    },
};

uploadEntities.Add(bulkExpandedTextAd);

var entityUploadParameters = new EntityUploadParameters
{
    Entities = uploadEntities,
    ResponseMode = ResponseMode.ErrorsAndResults,
    ResultFileDirectory = FileDirectory,
    ResultFileName = DownloadFileName,
    OverwriteResultFile = true,
};

var uploadResultEntities = (await bulkServiceManager.UploadEntitiesAsync(entityUploadParameters)).ToList();
List<BulkEntity> uploadEntities = new ArrayList<BulkEntity>();

// Map properties in the Bulk file to the BulkExpandedTextAd
BulkExpandedTextAd bulkExpandedTextAd = new BulkExpandedTextAd();

// 'Parent Id' column header in the Bulk file
bulkExpandedTextAd.setAdGroupId(adGroupIdKey);
// 'Ad Group' column header in the Bulk file
bulkExpandedTextAd.setAdGroupName("AdGroupNameGoesHere");
// 'Campaign' column header in the Bulk file
bulkExpandedTextAd.setCampaignName("ParentCampaignNameGoesHere");
// 'Client Id' column header in the Bulk file
bulkExpandedTextAd.setClientId("ClientIdGoesHere");

// Map properties in the Bulk file to the 
// ExpandedTextAd object of the Campaign Management service.
ExpandedTextAd expandedTextAd = new ExpandedTextAd();
// 'Ad Format Preference' column header in the Bulk file
expandedTextAd.setAdFormatPreference("All");
// 'Mobile Final Url' column header in the Bulk file
// Each Url is delimited by a semicolon (;) in the Bulk file
ArrayOfstring mobileFinalUrls = new ArrayOfstring();            
mobileFinalUrls.getStrings().add("https://mobile.contoso.com/womenshoesale");
expandedTextAd.setFinalMobileUrls(mobileFinalUrls);
// 'Final Url' column header in the Bulk file
// Each Url is delimited by a semicolon (;) in the Bulk file
ArrayOfstring finalUrls = new ArrayOfstring();            
finalUrls.getStrings().add("https://www.contoso.com/womenshoesale");
expandedTextAd.setFinalUrls(finalUrls);
// 'Id' column header in the Bulk file
expandedTextAd.setId(null);
// 'Path 1' column header in the Bulk file
expandedTextAd.setPath1("seattle");
// 'Path 2' column header in the Bulk file
expandedTextAd.setPath2("shoe sale");
// 'Status' column header in the Bulk file
expandedTextAd.setStatus(AdStatus.ACTIVE);
// 'Text' column header in the Bulk file
expandedTextAd.setText("Find New Customers & Increase Sales!");
// 'Text Part 2' column header in the Bulk file
expandedTextAd.setTextPart2("Start Advertising on Contoso Today.");
// 'Title Part 1' column header in the Bulk file
expandedTextAd.setTitlePart1("Contoso");
// 'Title Part 2' column header in the Bulk file
expandedTextAd.setTitlePart2("Quick & Easy Setup");
// 'Title Part 3' column header in the Bulk file
expandedTextAd.setTitlePart3("Seemless Integration");
// 'Tracking Template' column header in the Bulk file
expandedTextAd.setTrackingUrlTemplate(null);
// 'Custom Parameter' column header in the Bulk file
// Each custom parameter is delimited by a semicolon (;) in the Bulk file            
CustomParameters customParameters = new CustomParameters();
ArrayOfCustomParameter arrayOfCustomParameter = new ArrayOfCustomParameter();
CustomParameter customParameterA = new CustomParameter();
customParameterA.setKey("promoCode");
customParameterA.setValue("PROMO1");
arrayOfCustomParameter.getCustomParameters().add(customParameterA);
CustomParameter customParameterB = new CustomParameter();
customParameterB.setKey("season");
customParameterB.setValue("summer");
arrayOfCustomParameter.getCustomParameters().add(customParameterB);
customParameters.setParameters(arrayOfCustomParameter);
expandedTextAd.setUrlCustomParameters(customParameters);

bulkExpandedTextAd.setExpandedTextAd(expandedTextAd);

uploadEntities.add(bulkExpandedTextAd);

EntityUploadParameters entityUploadParameters = new EntityUploadParameters();
entityUploadParameters.setEntities(uploadEntities);
entityUploadParameters.setOverwriteResultFile(true);
entityUploadParameters.setResultFileDirectory(new File(FileDirectory));
entityUploadParameters.setResultFileName(ResultFileName);
entityUploadParameters.setResponseMode(ResponseMode.ERRORS_AND_RESULTS);

BulkEntityIterable uploadResultEntities = bulkServiceManager.uploadEntitiesAsync(
    entityUploadParameters, 
    null, 
    null
).get();
# Map properties in the Bulk file to the BulkExpandedTextAd
bulk_expanded_text_ad=BulkExpandedTextAd()

# 'Parent Id' column header in the Bulk file
bulk_expanded_text_ad.ad_group_id=AD_GROUP_ID_KEY
# 'Ad Group' column header in the Bulk file
bulk_expanded_text_ad.AdGroupName='AdGroupNameGoesHere'
# 'Campaign' column header in the Bulk file
bulk_expanded_text_ad.CampaignName='ParentCampaignNameGoesHere'
# 'Client Id' column header in the Bulk file
bulk_expanded_text_ad.ClientId='ClientIdGoesHere'

# Map properties in the Bulk file to the 
# ExpandedTextAd object of the Campaign Management service.
expanded_text_ad=set_elements_to_none(campaign_service.factory.create('ExpandedTextAd'))
# 'Ad Format Preference' column header in the Bulk file
expanded_text_ad.AdFormatPreference='All'
# 'Mobile Final Url' column header in the Bulk file
# Each Url is delimited by a semicolon (;) in the Bulk file
mobile_final_urls=campaign_service.factory.create('ns3:ArrayOfstring')
mobile_final_urls.string.append('https://mobile.contoso.com/womenshoesale')
expanded_text_ad.FinalUrls=mobile_final_urls
# 'Final Url' column header in the Bulk file
# Each Url is delimited by a semicolon (;) in the Bulk file
final_urls=campaign_service.factory.create('ns3:ArrayOfstring')
final_urls.string.append('https://www.contoso.com/womenshoesale')
expanded_text_ad.FinalUrls=final_urls
# 'Id' column header in the Bulk file
expanded_text_ad.Id=None
# 'Path 1' column header in the Bulk file
expanded_text_ad.Path1='seattle'
# 'Path 2' column header in the Bulk file
expanded_text_ad.Path2='shoe sale'
# 'Status' column header in the Bulk file
expanded_text_ad.Status='Active'
# 'Text' column header in the Bulk file
expanded_text_ad.Text='Find New Customers & Increase Sales!'
# 'Text Part 2' column header in the Bulk file
expanded_text_ad.TextPart2='Start Advertising on Contoso Today.'
# 'Title Part 1' column header in the Bulk file
expanded_text_ad.TitlePart1='Contoso'
# 'Title Part 2' column header in the Bulk file
expanded_text_ad.TitlePart2='Quick & Easy Setup'
# 'Title Part 3' column header in the Bulk file
expanded_text_ad.TitlePart3='Seemless Integration'
# 'Tracking Template' column header in the Bulk file
expanded_text_ad.TrackingUrlTemplate=None
# 'Custom Parameter' column header in the Bulk file
# Each custom parameter is delimited by a semicolon (;) in the Bulk file            
custom_parameters=set_elements_to_none(campaign_service.factory.create('CustomParameters'))
array_of_custom_parameter=campaign_service.factory.create('ArrayOfCustomParameter')
custom_parameter_a=set_elements_to_none(campaign_service.factory.create('CustomParameter'))
custom_parameter_a.Key='promoCode'
custom_parameter_a.Value='PROMO1'
array_of_custom_parameter.CustomParameter.append(custom_parameter_a)
custom_parameter_b=set_elements_to_none(campaign_service.factory.create('CustomParameter'))
custom_parameter_b.Key='season'
custom_parameter_b.Value='summer'
array_of_custom_parameter.CustomParameter.append(custom_parameter_b)
custom_parameters.Parameters=array_of_custom_parameter
expanded_text_ad.UrlCustomParameters=custom_parameters

bulk_expanded_text_ad.ad=expanded_text_ad

upload_entities.append(bulk_expanded_text_ad)

entity_upload_parameters=EntityUploadParameters(
    entities=upload_entities,
    overwrite_result_file=True,
    result_file_directory=FILE_DIRECTORY,
    result_file_name=RESULT_FILE_NAME,
    response_mode='ErrorsAndResults'
)

upload_result_entities=bulk_service_manager.upload_entities(
    entity_upload_parameters=entity_upload_parameters, 
    progress=None
)

อัปเดตด้วย delete_value

หากต้องการลบการตั้งค่าที่มีอยู่ คุณไม่ควรเขียนสตริงที่ว่างเปล่า ("") ไปยังไฟล์ Bulk เนื่องจากสตริงดังกล่าวถูกละเว้นโดยบริการ Bulk ใช้สตริง "delete_value" ที่สงวนไว้เพื่อลบหรือรีเซ็ตค่าของเขตข้อมูลที่เลือกได้ ถ้าคุณใช้สตริง "delete_value" ที่สงวนไว้ในเขตข้อมูลที่เลือกได้ การตั้งค่าก่อนหน้าจะถูกลบ ตัวอย่างเช่น ถ้าคุณตั้งค่าเขตข้อมูล พารามิเตอร์แบบกําหนดเอง ของระเบียน โฆษณาข้อความแบบขยาย เป็น "delete_value" พารามิเตอร์แบบกําหนดเองก่อนหน้านี้ทั้งหมดจะถูกลบออกจากโฆษณาแบบข้อความที่ขยาย ในทํานองเดียวกัน หากคุณตั้งค่าเขตข้อมูล เทมเพลตการติดตาม ของระเบียน โฆษณาข้อความแบบขยาย เป็น "delete_value" เทมเพลตการติดตามก่อนหน้าจะถูกลบออกจากโฆษณาแบบข้อความที่ขยาย สําหรับรายละเอียดเพิ่มเติมเกี่ยวกับ "delete_value" ดู Schema ไฟล์จํานวนมาก - อัปเดตด้วย delete_value

BulkFileWriter จะเขียน "delete_value" โดยอัตโนมัติตามความเหมาะสม เนื่องจาก SDK แมป ออบเจ็กต์ API การจัดการแคมเปญกับเนื้อหาของไฟล์จํานวนมาก คุณจึงไม่สามารถตั้งค่าสตริง "delete_value" สําหรับคุณสมบัติกับข้อมูลประเภทอื่น ได้อย่างชัดเจน ในกรณีเหล่านั้น คุณสามารถใช้ไวยากรณ์เดียวกันกับที่คุณใช้ในการอัปเดตวัตถุผ่าน API การจัดการแคมเปญ ในตัวอย่างด้านล่างโดยการตั้งค่า UrlCustomParameters เป็นวัตถุ CustomParameters ที่ว่างเปล่า SDK จะเขียน "delete_value" ในเขตข้อมูลพารามิเตอร์แบบกําหนดเองของระเบียนโฆษณาข้อความแบบขยาย ในทํานองเดียวกัน โดยการตั้งค่า TrackingUrlTemplate เป็นสตริงว่าง SDK จะเขียน "delete_value" ในเขตข้อมูลเทมเพลตการติดตามของระเบียนโฆษณาข้อความแบบขยาย ไวยากรณ์ตัวอย่างภายในออบเจ็กต์ ExpandedTextAd เหมือนกับวิธีที่คุณลบการตั้งค่า previus ผ่านการดําเนินการบริการ UpdateAds ผ่าน API การจัดการแคมเปญ

สิ่งสำคัญ

อย่าใช้สตริงว่าง ("") หรือไวยากรณ์ "delete_value" เมื่อคุณสร้างเอนทิตีกลุ่ม สตริง "delete_value" ที่สงวนไว้จะใช้ได้สําหรับการอัปเดตระเบียนจํานวนมากเท่านั้น คุณไม่ควรตั้งค่าคุณสมบัติ หรือตั้งค่าเป็นค่า Null ที่เทียบเท่ากัน

var bulkExpandedTextAd = new BulkExpandedTextAd
{
    AdGroupId = adGroupIdKey,
    ExpandedTextAd = new ExpandedTextAd
    {
        Id = expandedTextAdIdKey,
        TrackingUrlTemplate = "",
        UrlCustomParameters = new CustomParameters { }
    },
};
BulkExpandedTextAd bulkExpandedTextAd = new BulkExpandedTextAd();
bulkExpandedTextAd.setAdGroupId(expandedTextAdIdKey);
ExpandedTextAd expandedTextAd = new ExpandedTextAd();
expandedTextAd.setId(adIdKey);
expandedTextAd.setTrackingUrlTemplate("");       
CustomParameters customParameters = new CustomParameters();
expandedTextAd.setUrlCustomParameters(customParameters);
bulkExpandedTextAd.setExpandedTextAd(expandedTextAd);
bulk_expanded_text_ad=BulkExpandedTextAd()
bulk_expanded_text_ad.ad_group_id=AD_GROUP_ID_KEY
expanded_text_ad=set_elements_to_none(campaign_service.factory.create('ExpandedTextAd'))
expanded_text_ad.Id=EXPANDED_TEXT_AD_ID_KEY
expanded_text_ad.TrackingUrlTemplate=''         
custom_parameters=set_elements_to_none(campaign_service.factory.create('CustomParameters'))
expanded_text_ad.UrlCustomParameters=custom_parameters
bulk_expanded_text_ad.ad=expanded_text_ad

ดาวน์โหลดและอัปโหลด

BulkServiceManager สนับสนุนการดาวน์โหลดจํานวนมากที่ยืดหยุ่นและอัปโหลดเวิร์กโฟลว์

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

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

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

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

การทําให้พื้นหลังสมบูรณ์ด้วย BulkServiceManager

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

public async Task RunAsync(AuthorizationData authorizationData)
{
    var bulkServiceManager = new BulkServiceManager(authorizationData);

    var progress = new Progress<BulkOperationProgressInfo>(x =>
        Console.WriteLine(String.Format("{0} % Complete", x.PercentComplete.ToString(CultureInfo.InvariantCulture))));

    var downloadParameters = new DownloadParameters
    {
        CampaignIds = null,
        DataScope = DataScope.EntityData,
        Entities = DownloadEntity.Keywords,
        FileType = DownloadFileType.Csv,
        LastSyncTimeInUTC = null,
        ResultFileDirectory = FileDirectory,
        ResultFileName = ResultFileName,
        OverwriteResultFile = false  // Set this value true if you want to overwrite the same file.
    };

    // Sets the time interval in milliseconds between two status polling attempts. The default value is 5000 (5 seconds).
    bulkServiceManager.StatusPollIntervalInMilliseconds = 5000;
    // Sets the timeout of the HttpClient download operation. The default value is 100000 (100s).
    bulkServiceManager.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 BulkServiceManager will submit your download request to the Bulk service, 
    // poll the service until completed, and download the file to your local directory.

    var resultFile = await bulkServiceManager.DownloadFileAsync(
        parameters: downloadParameters,
        progress: progress,
        cancellationToken: tokenSource.Token
    );

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

Progress<BulkOperationProgressInfo> progress = new Progress<BulkOperationProgressInfo>() {
    @Override
    public void report(BulkOperationProgressInfo value) {
        System.out.println(value.getPercentComplete() + "% Complete\n");
    }
};

DownloadParameters downloadParameters = new DownloadParameters();
downloadParameters.setCampaignIds(null);
ArrayList<DataScope> dataScope = new ArrayList<DataScope>();
dataScope.add(DataScope.ENTITY_DATA);
downloadParameters.setDataScope(dataScope);
downloadParameters.setFileType(FileType);
downloadParameters.setLastSyncTimeInUTC(null);
ArrayList<DownloadEntity> bulkDownloadEntities = new ArrayList<DownloadEntity>();
bulkDownloadEntities.add(DownloadEntity.KEYWORDS);
downloadParameters.setEntities(bulkDownloadEntities);
downloadParameters.setResultFileDirectory(new File(FileDirectory));
downloadParameters.setResultFileName(ResultFileName);
downloadParameters.setOverwriteResultFile(true);    // Set this value true if you want to overwrite the same file.

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

// The BulkServiceManager will submit your download request to the Bulk 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 = bulkServiceManager.downloadFileAsync(
    downloadParameters, 
    progress, 
    null
).get(3600000, TimeUnit.MILLISECONDS);

System.out.printf("Download result file: %s\n", resultFile.getName());
bulk_service_manager = BulkServiceManager(
    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,
)
        
download_parameters = DownloadParameters(
    campaign_ids=None,
    data_scope=['EntityData'],
    entities=entities,
    file_type=FILE_TYPE,
    last_sync_time_in_utc=None,
    result_file_directory = FILE_DIRECTORY, 
    result_file_name = DOWNLOAD_FILE_NAME, 
    # Set this value true if you want to overwrite the same file.
    overwrite_result_file = True, 
    # You may optionally cancel the download after a specified time interval.
    timeout_in_milliseconds=3600000 
)

# The BulkServiceManager will submit your download request to the Bulk service, 
# poll the service until completed, and download the file to your local directory.
result_file_path = bulk_service_manager.download_file(
    download_parameters=download_parameters, 
    progress = None
)

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

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

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

public async Task RunAsync(AuthorizationData authorizationData)
{
    var bulkServiceManager = new BulkServiceManager(authorizationData);

    var submitDownloadParameters = new SubmitDownloadParameters
    {
        CampaignIds = null,
        DataScope = DataScope.EntityData,
        Entities = DownloadEntity.Keywords,
        FileType = DownloadFileType.Csv,
        LastSyncTimeInUTC = null
    };

    var bulkDownloadOperation = await bulkServiceManager.SubmitDownloadAsync(submitDownloadParameters);

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

    BulkOperationStatus<DownloadStatus> downloadStatus = await bulkDownloadOperation.TrackAsync(
        null, 
        tokenSource.Token
    );

    var resultFilePath = await bulkDownloadOperation.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));
}
BulkServiceManager bulkServiceManager = new BulkServiceManager(authorizationData);

SubmitDownloadParameters submitDownloadParameters = new SubmitDownloadParameters();
submitDownloadParameters.setCampaignIds(null);
ArrayList<DataScope> dataScope = new ArrayList<DataScope>();
dataScope.add(DataScope.ENTITY_DATA);
submitDownloadParameters.setDataScope(dataScope);
submitDownloadParameters.setFileType(FileType);
submitDownloadParameters.setLastSyncTimeInUTC(null);
ArrayList<DownloadEntity> bulkDownloadEntities = new ArrayList<DownloadEntity>();
bulkDownloadEntities.add(DownloadEntity.KEYWORDS);
submitDownloadParameters.setEntities(bulkDownloadEntities);

// Submit the download request. You can use the BulkDownloadOperation result to track status yourself using getStatusAsync,
// or use trackAsync to indicate that the application should wait until the download status is completed.

BulkDownloadOperation bulkDownloadOperation = bulkServiceManager.submitDownloadAsync(
    submitDownloadParameters,
    null
).get();

// You may optionally cancel the trackAsync operation after a specified time interval.
BulkOperationStatus<DownloadStatus> downloadStatus = bulkDownloadOperation.trackAsync(
    null
).get(3600000, TimeUnit.MILLISECONDS);

File resultFile = bulkDownloadOperation.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()));
bulk_service_manager = BulkServiceManager(
    authorization_data=authorization_data, 
    poll_interval_in_milliseconds = 5000, 
    environment = ENVIRONMENT,
)

submit_download_parameters = SubmitDownloadParameters(
    data_scope = [ 'EntityData' ],
    entities = [ 'Campaigns', 'AdGroups', 'Keywords', 'Ads' ],
    file_type = 'Csv',
    campaign_ids = None,
    last_sync_time_in_utc = None,
    performance_stats_date_range = None
)

bulk_download_operation = bulk_service_manager.submit_download(submit_download_parameters)

# You may optionally cancel the track() operation after a specified time interval.
download_status = bulk_download_operation.track(timeout_in_milliseconds=3600000)
    
result_file_path = bulk_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))

ดาวน์โหลดผลลัพธ์ที่มี BulkServiceManager

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

public async Task RunAsync(AuthorizationData authorizationData)
{
    var bulkServiceManager = new BulkServiceManager(authorizationData);

    var progress = new Progress<BulkOperationProgressInfo>(x =>
        Console.WriteLine(String.Format("{0} % Complete", x.PercentComplete.ToString(CultureInfo.InvariantCulture))));

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

    var bulkDownloadOperation = new BulkDownloadOperation(requestId, authorizationData);

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

    var resultFilePath = await bulkDownloadOperation.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}", bulkOperationStatus.Status));
    Console.WriteLine(String.Format("TrackingId: {0}\n", bulkOperationStatus.TrackingId));
}
Progress<BulkOperationProgressInfo> progress = new Progress<BulkOperationProgressInfo>() {
    @Override
    public void report(BulkOperationProgressInfo value) {
        System.out.println(value.getPercentComplete() + "% Complete\n");
    }
};

java.lang.String requestId = RequestIdGoesHere;

BulkDownloadOperation bulkDownloadOperation = new BulkDownloadOperation(requestId, authorizationData);

// You may optionally cancel the trackAsync operation after a specified time interval.
BulkOperationStatus<DownloadStatus> downloadStatus = bulkDownloadOperation.trackAsync(
    progress, 
    null
).get(3600000, TimeUnit.MILLISECONDS);

System.out.printf(
    "Download Status:\nPercentComplete: %s\nResultFileUrl: %s\nStatus: %s\n",
    downloadStatus.getPercentComplete(), downloadStatus.getResultFileUrl(), downloadStatus.getStatus()
);

File resultFile = bulkDownloadOperation.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 same file.
    null
).get();

System.out.println(String.format("Download result file: %s", resultFile.getName()));
System.out.println(String.format("Status: %s", downloadStatus.getStatus()));
System.out.println(String.format("TrackingId: %s\n", downloadStatus.getTrackingId()));
request_id = RequestIdGoesHere

bulk_download_operation = BulkDownloadOperation(
    request_id = request_id, 
    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.
bulk_operation_status = bulk_download_operation.track(timeout_in_milliseconds=3600000)

result_file_path = bulk_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))
print("Status: {0}\n".format(bulk_operation_status.status))

Poll และลองใหม่

Poll สําหรับการดาวน์โหลดและอัปโหลดผลลัพธ์ในช่วงเวลาที่เหมาะสม คุณรู้จักข้อมูลของคุณดีกว่าทุกคน ตัวอย่างเช่นหากคุณดาวน์โหลดบัญชีที่มีคําหลักน้อยกว่าหนึ่งล้านคําให้พิจารณาการโพลล์ที่ช่วงเวลา 5 ถึง 20 วินาที หากบัญชีมีคําหลักประมาณหนึ่งล้านคํา ให้พิจารณาการโพลล์ในช่วงเวลาหนึ่งนาทีหลังจากรอห้านาที สําหรับบัญชีที่มีคําหลักประมาณสี่ล้านคํา ให้พิจารณาการโพลล์ในช่วงเวลาหนึ่งนาทีหลังจากรอ 10 นาที

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

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

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

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

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

สิ่งสำคัญ

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

public async Task RunAsync(AuthorizationData authorizationData)
{
    var bulkServiceManager = new BulkServiceManager(authorizationData);

    var progress = new Progress<BulkOperationProgressInfo>(x =>
        Console.WriteLine(String.Format("{0} % Complete", x.PercentComplete.ToString(CultureInfo.InvariantCulture)))
    );

    var downloadParameters = new DownloadParameters
    {
        CampaignIds = null,
        DataScope = DataScope.EntityData,
        Entities = DownloadEntity.Keywords,
        FileType = DownloadFileType.Csv,
        LastSyncTimeInUTC = null,
        ResultFileDirectory = FileDirectory,
        ResultFileName = ResultFileName,
        OverwriteResultFile = false    // Set this value true if you want to overwrite the same file.
    };

    // 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 BulkServiceManager instance.

    bulkServiceManager.WorkingDirectory = FileDirectory;

    // The DownloadEntitiesAsync method returns IEnumerable<BulkEntity>, so the download file will not
    // be accessible e.g. for CleanupTempFiles until you iterate over the result e.g. via ToList().

    var resultEntities = (await bulkServiceManager.DownloadEntitiesAsync(
        downloadParameters
    )).ToList();

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

    bulkServiceManager.CleanupTempFiles();
}
BulkServiceManager bulkServiceManager = new BulkServiceManager(authorizationData);

Progress<BulkOperationProgressInfo> progress = new Progress<BulkOperationProgressInfo>() {
    @Override
    public void report(BulkOperationProgressInfo value) {
        System.out.println(value.getPercentComplete() + "% Complete\n");
    }
};

DownloadParameters downloadParameters = new DownloadParameters();
downloadParameters.setCampaignIds(null);
ArrayList<DataScope> dataScope = new ArrayList<DataScope>();
dataScope.add(DataScope.ENTITY_DATA);
downloadParameters.setDataScope(dataScope);
downloadParameters.setFileType(FileType);
downloadParameters.setLastSyncTimeInUTC(null);
ArrayList<DownloadEntity> bulkDownloadEntities = new ArrayList<DownloadEntity>();
bulkDownloadEntities.add(DownloadEntity.KEYWORDS);
downloadParameters.setEntities(bulkDownloadEntities);
downloadParameters.setResultFileDirectory(new File(FileDirectory));
downloadParameters.setResultFileName(ResultFileName);
downloadParameters.setOverwriteResultFile(true);    // Set this value true if you want to overwrite the same file.

// The system temp directory will be used if another working directory is not specified. If you are 
// using a cloud 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 BulkServiceManager instance.

bulkServiceManager.setWorkingDirectory(new File(FileDirectory));

// The downloadEntitiesAsync method returns BulkEntityIterable, so the download file will not
// be accessible e.g. for cleanupTempFiles until you iterate over the result and close the BulkEntityIterable instance.

BulkEntityIterable tempEntities = bulkServiceManager.downloadEntitiesAsync(
    downloadParameters,
    null,
    null
).get();

ArrayList<BulkEntity> resultEntities = new ArrayList<BulkEntity>();
for (BulkEntity entity : tempEntities) {
    resultEntities.add(entity);
}

tempEntities.close();

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

bulkServiceManager.cleanupTempFiles();

ดูเพิ่มเติม

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