Messenger: attachment type 'video' not working correctly?

2.7k Views Asked by At

According to https://developers.facebook.com/docs/messenger-platform/send-api-reference/video-attachment I should be able to send video's via messenger. I ideally want to send youtube videos with a start and end time, but that does not seem to work.

I am currently trying to get it work in any such way, so i have the video on FB currently and even that isn't working.

python code

    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) Failed to fetch the file from the url","type":"OAuthException","code":100,"error_subcode":2018008,"fbtrace_id":"BjJzB1J8/42"}}

3

There are 3 best solutions below

0
On

You need to supply the URL to the video file (for example MP4), not the URL of page containing the video (for example a YouTube URL).

This can be seen in the example code in 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"    
1
On

Sending Youtube videos in your Facebook Messenger bot is now possible if you use the open graph template.

A message object would then look like this:

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

As of today, this works (you need to add the image url of the screenshot):

message: {
  text,
  attachment: {
    type: "template",
    payload: {
      template_type: "generic",
      elements: [
        {
          title: "El espía",
          image_url: "https://i.ytimg.com/vi/yj2r6KPKV1w/hqdefault.jpg?sqp=-oaymwEcCOADEI4CSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLAGKGjilp1gvYUv6c5dL_oveZ8LYg",
          default_action: {
            type: "web_url",
            url: "https://www.youtube.com/watch?v=yj2r6KPKV1w",                            
          },
        }
      ],
    },
  },
},