【问题标题】:Messenger: attachment type 'video' not working correctly?Messenger:附件类型“视频”无法正常工作?
【发布时间】:2017-05-06 07:27:21
【问题描述】:

根据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}, "recipient": {"id": "1297603110290455" }, "message": {"attachment": {"type": "video", "payload": {"url": "https://www.facebook.com/587721184763189/videos/596530243882283/"}}}}

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

【问题讨论】:

    标签: facebook facebook-messenger


    【解决方案1】:

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

    这可以在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"    
    

    【讨论】:

      【解决方案2】:

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

      消息对象将如下所示:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-27
        • 1970-01-01
        • 1970-01-01
        • 2013-11-20
        相关资源
        最近更新 更多