首页 文章

如何在Facebook批量API请求中指定API版本?

提问于
浏览
11

Facebook批量API请求允许调用者在单个HTTP POST中指定多个API endpoints .

帖子是基本网址:https://graph.facebook.com .

帖子的主体包含一个JSON哈希,其中包含要在“relative_url”字段中调用的相对URL,例如“我/饲料” .

如何在此调用中指定API版本?

例如,要点击2.2版本的API,我应该发布到https://graph.facebook.com/v2.2/还是在relative_url中指定"v2.2/me/feed"?

截至2015年2月26日,Facebook API文档在这一点上尚不清楚:https://developers.facebook.com/docs/graph-api/making-multiple-requests

1 回答

  • 10

    您可能需要输入相对URL . 这是营销批处理API文档中的example

    curl -F 'access_token=______' 
      -F 'test1=@./test1.jpg'  
      -F 'batch=[
                 {
                  "method": "POST",
                  "name": "create_creative",
                  "relative_url": "<API_VERSION>/act_187687683/adcreatives",
                  "attached_files": "test1",
                  "body": "title=Test title&body=Test body&link_url=http://www.test12345.com&image_file=test1.jpg"
                 },
                 {
                  "method": "POST",
                  "relative_url": "<API_VERSION>/act_187687683/adgroups",
                  "body": "campaign_id=6004163746239&redownload=1&bid_type=CPC&bid_info={\"clicks\":150}&creative={\"creative_id\":\"{result=create_creative:$.id}\"}&targeting={\"countries\":[\"US\"]}&name=test1"
                 },
                 {
                  "method": "POST",
                  "relative_url": "<API_VERSION>/act_187687683/adgroups",
                  "body": "campaign_id=6004163746239&redownload=1&bid_type=CPC&bid_info={\"clicks\":150}&creative={\"creative_id\":\"{result=create_creative:$.id}\"}&targeting={\"countries\":[\"GB\"]}&name=test2"
                 },
                 {
                  "method": "POST",
                  "relative_url": "<API_VERSION>/act_187687683/adgroups",
                  "body": "campaign_id=6004163746239&redownload=1&bid_type=CPC&bid_info={\"clicks\":150}&creative={\"creative_id\":\"{result=create_creative:$.id}\"}&targeting={\"countries\":[\"IE\"]}&name=test3"
                 }
                ]' https://graph.facebook.com/
    

    我认为这也是其他请求的共同点 .

    各种其他阅读资源

    1.)来自here

    将版本标识符预先挂起到请求路径的开头 . 例如,这是对v2.2的调用:GET graph.facebook.com
    /v2.2/me
    这适用于所有版本,采用以下一般形式:GET graph.facebook.com
    /vX.Y/

    2.)将它放在网址中似乎是Dialogs and Social plugins

    对话框版本化路径不仅适用于API endpoints ,它们也适用于对话框和社交插件 . 例如,如果要为Web应用程序生成Facebook登录对话框,可以在生成对话框的 endpoints 前面添加版本号:https://www.facebook.com/v2.0/dialog/oauth?
    CLIENT_ID = {应用ID}
    &REDIRECT_URI = {重定向-URI}
    社交插件如果您使用社交插件的HTML5或xfbml版本,则呈现的版本将由您初始化JavaScript SDK时指定的版本决定 . 如果您要插入我们其中一个插件的iframe或纯链接版本,您需要将版本号添加到插件的源路径:<iframe
    SRC =“// www.facebook.com/v2.0/plugins/like.php?href=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fplugins%2F&width&layout=standard&action=like&amp ; show_faces = true&amp; share = true&amp; height = 80&amp; appId = 634262946633418“scrolling =”no“frameborder =”0“style =”border:none; overflow:hidden; height:80px;“ allowTransparency =“true”> </ iframe>

相关问题