简体   繁体   中英

Facebook send API sending audio issue

Can't send audio through facebook send api. It always returns with an HTTP 400 Bad Request. I use python and urllib for the http request.

Json:

  'recipient':{ 'id' : userId }, 'message' : { 'attachment' : { 'type' : 'audio', 'payload' : { 'url' : url } } } } 

Request:

def send_msg(userId,data,accessKey):
    HEADERS = {
        'Content-Type':'application/json'
    }
    url = 'https://graph.facebook.com/v2.6/me/messages?access_token='+accessKey
    msg_json = {
       'message' : {
        'attachment' : {
            'type' : 'audio',
            'payload' : {
                'url' : url
            }
        }
    }


    data = json.dumps(msg_json).encode('utf-8')
    req = urllib.request.Request(url,data,HEADERS)
    resp = urllib.request.urlopen(req)

The code works on image and file attachment but it doesn't work on audio.

json蓝图中的问题是缺少“内容类型”,该内容类型的值应为“ audio / mpeg”,该值指定mp3音频上传的文件格式

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM