【问题标题】:Facebook Graph API BATCH request with post method使用 post 方法的 Facebook Graph API BATCH 请求
【发布时间】:2018-10-18 11:42:52
【问题描述】:

我正在尝试使用 axios 发送带有图形 api 批处理请求的批处理请求。 当我尝试使用邮递员时,我尝试了以下操作 - 我正在尝试发布带有批处理请求的发送 api。

url = https://graph.facebook.com?access_token=EA...`.
raw body  = `{
    "batch":[
  {
    "method": "POST",
    "relative_url": "me/messages?access_token=<ACCESS_TOKEN>",
    "body": "{ \"messaging_type\": \"MESSAGE_TAG\",\r\n         \"tag\": \"ISSUE_RESOLUTION\",\r\n        \"recipient\": {\r\n          \"id\": \"1111944272264076\"\r\n        },\r\n        \"message\": {\r\n          \"text\": \"hello, world!\"\r\n        }}"
  }
]
}

反应是

[
    {
        "code": 400,
        "headers": [
            {
                "name": "WWW-Authenticate",
                "value": "OAuth \"Facebook Platform\" \"invalid_request\" \"(#100) The parameter recipient is required\""
            },
            {
                "name": "Expires",
                "value": "Sat, 01 Jan 2000 00:00:00 GMT"
            },
            {
                "name": "Strict-Transport-Security",
                "value": "max-age=15552000; preload"
            },
            {
                "name": "Facebook-API-Version",
                "value": "v2.10"
            },
            {
                "name": "Content-Type",
                "value": "text/javascript; charset=UTF-8"
            },
            {
                "name": "X-App-Usage",
                "value": "{\"call_count\":0,\"total_cputime\":0,\"total_time\":0}"
            },
            {
                "name": "Access-Control-Allow-Origin",
                "value": "*"
            },
            {
                "name": "Cache-Control",
                "value": "no-store"
            },
            {
                "name": "Vary",
                "value": "Accept-Encoding"
            },
            {
                "name": "Pragma",
                "value": "no-cache"
            }
        ],
        "body": "{\"error\":{\"message\":\"(#100) The parameter recipient is required\",\"type\":\"OAuthException\",\"code\":100,\"fbtrace_id\":\"BdrR5exbYCu\"}}"
    }
]

响应码是 200。我已经在正文中给出了收件人。

【问题讨论】:

    标签: javascript node.js facebook facebook-graph-api messenger


    【解决方案1】:

    您不需要对整个正文进行 URL 编码。只有每个参数的内容。试试这个作为请求的主体:

    {
     "batch":[
      {
       "method":"POST",
       "relative_url":"me/messages", 
       "body": "recipient={\"id\": \"1111944272264076\"}&message={\"text\": \"hello, world!\"}"
      }
     ]
    }
    

    注意:我只是对字符进行转义,而不是 URL 编码。使代码更具可读性

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多