2016-10-12 106 views
0

我使用Facebook的營銷API來創建廣告。我已經成功製作了包含單幅圖片的廣告,但現在我的要求是使用多張圖片製作廣告。我不知道如何創建這個。Facebook廣告與Facebook營銷API的多個圖像

我正在用C#在ASP.NET MVC中工作。我試圖從facebook上找到c#SDK,並且找到了一個,但是在那裏使用的API太舊了,而且facebook也沒有接受任何API請求。

然後開始按照facebook指南使用圖API和市場營銷API說明。我在javascript和html5中通過這些鏈接的幫助創建了一個頁面,並且所有工作都正常。但現在困擾於用多個圖像創建廣告。

請有人提出這個想法,我該如何實現這一點。我的工作代碼是:

========================================= ========================================================

function CarrouselCreative(images, actID, adSetID, campID, callback) { 

    var apiURL = "/" + actID + "/adcreatives"; 
    var adCreativeName = $("#hdnCreativeName").val() + "-Creative"; 
    var adCreativeTitle = $("#txtCreativeAdTitle").val(); 
    var adCreativeBody = $("#txtAdBodyMessage").val(); 
    var imageURL = "http://www.test.com/wp-content/uploads/2015/04/maplegrove.jpeg"; 

    var url1 = encodeURI("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTtkBB90ZG2Sk_MaNIvlz9pszpi9JJFnU38ol4Ac-NoDCuX3kGY"); 
    var url2 = encodeURI("https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRrGNQ5PLrhha-T9DAInIw0RtzqfyJUasP1Q-jfrt0nOJ2-qxe6"); 
    var url3 = encodeURI("http://www.test.com"); 


    var object_story = { 
     "page_id": "18105454546788 ", 
     "link ": "http: //www.test.com", 
     "link_data": { 
      "caption": "My caption", 
      "child_attachments": [{ 
       "description": "$8.99", 
       "image_hash": "2423690a56e826ce4af", 
       "link": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTtkBB90ZG2Sk_MaNIvlz9pszpi9JJFnU38ol4Ac-NoDCuX3kGY", 
       "name": "Product 1", 
       "object_type": "PHOTO" 
      }, { 
       "description": "$9.99", 
       "image_hash": "4ff9caa3f714c8096ee", 
       "link": "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRrGNQ5PLrhha-T9DAInIw0RtzqfyJUasP1Q-jfrt0nOJ2-qxe6", 
       "name": "Product 2", 
       "object_type": "PHOTO" 
      }] 
     } 
    } 
    debugger; 
    var story = JSON.stringify(object_story); 
    FB.api(apiURL, 'POST', { 
     name: adCreativeName, 
     title: adCreativeTitle, 
     body: adCreativeBody, 
     object_story_spec: story 
    }, function (response) { 
     if (response.error) { 
      alert("creativeID: " + response.error.error_user_title + " : " + response.error.error_user_msg); 
      FB.api(campID, 'DELETE'); 
     } 
     else { 
      callback(response.id); 
     } 
    }); 
} 

======= ================================================== ========= 我需要添加與以下錯誤消息相關的詳細信息。 「您的廣告必須包含以下功能之一:照片,視頻,鏈接,模板鏈接,文字或優惠,請添加其中一項資源並重試。」

在這裏,我需要做出改變.......

var object_story = { 
     "page_id": "18105454546788 ", 
     "link ": "http: //www.test.com", 
     "link_data": { 
      "caption": "My caption", 
      "child_attachments": [{ 
       "description": "$8.99", 
       "image_hash": "2423690a56e826ce4af", 
       "link": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTtkBB90ZG2Sk_MaNIvlz9pszpi9JJFnU38ol4Ac-NoDCuX3kGY", 
       "name": "Product 1", 
       "object_type": "PHOTO" 
      }, { 
       "description": "$9.99", 
       "image_hash": "4ff9caa3f714c8096ee", 
       "link": "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRrGNQ5PLrhha-T9DAInIw0RtzqfyJUasP1Q-jfrt0nOJ2-qxe6", 
       "name": "Product 2", 
       "object_type": "PHOTO" 
      }] 
     } 
    } 

回答

0

上述問題,我在我的C#代碼使用Python廣告API解決。 Facebook提供了完整的指導方針來創建各種廣告,包括帶有多個圖像的carousal廣告手段廣告。

因此,使用Python腳本重新創建了完整的代碼,並在C#中實現了該代碼。現在我的廣告應用順利運行。