Messenger:附件类型'视频'不正常工作?

时间:2016-12-21 00:04:47

标签: facebook facebook-messenger

根据https://developers.facebook.com/docs/messenger-platform/send-api-reference/video-attachment,我应该可以通过信使发送视频。理想情况下,我想发送带有开始和结束时间的youtube视频,但这似乎不起作用。

我目前正试图让它以任何这种方式运作,所以我目前在FB上播放视频,甚至还没有工作。

python代码

    data = OrderedDict()
    data['sender'] = {"id": APP_ID}
    data['recipient'] = {"id": recipient}
    data['message'] = {
            "attachment": {
                "type": "video",
                "payload": {"url": "https://www.facebook.com/587721184763189/videos/596530243882283/"}
            }
        }

    data = json.dumps(data)
    print("data: ", data)

    r = requests.post("https://graph.facebook.com/v2.6/me/messages",
        params={"access_token": token},
        data=data,
        headers={'Content-type': 'application/json'},
        timeout=60)
    if r.status_code != requests.codes.ok:
         print(r.text)

2016-12-20T23:45:40.685949 + 00:00 app [web.1]:data:{" sender":{" id":744391742366207},&# 34;收件人":{" id":" 1297603110290455"},"消息":{"附件":{&#34 ;键入":"视频","有效负载":{" url":" https://www.facebook.com/587721184763189/videos/596530243882283/"}}} }

2016-12-20T23:45:41.396419 + 00:00 app [web.1]:{" error":{" message":"(#100 )无法从网址中获取文件","键入":" OAuthException"," code":100," error_subcode" :2018008," fbtrace_id":" BjJzB1J8 / 42"}}

2 个答案:

答案 0 :(得分:1)

如果您使用开放图表模板,现在可以在您的Facebook Messenger机器人中发送Youtube视频。

消息对象将如下所示:

"message": {
           "attachment": {
               "type": "template",
               "payload": {
                   "template_type": "open_graph",
                   "elements": [
                       {
                           "url": "https://www.youtube.com/watch?v=whatever"
                       }
                   ]
               }
           }
       }

答案 1 :(得分:0)

您需要提供视频文件的网址(例如MP4),而不是包含视频的网页网址(例如YouTube网址)。

这可以在Facebook's documentation

中的示例代码中看到
curl -X POST -H "Content-Type: application/json" -d '{
  "recipient":{
    "id":"USER_ID"
  },
  "message":{
    "attachment":{
      "type":"video",
      "payload":{
        "url":"https://petersapparel.com/bin/clip.mp4"
      }
    }
  }
}' "https://graph.facebook.com/v2.6/me/messages?access_token=PAGE_ACCESS_TOKEN"