0

我正在尝试为我的 python facebook bot 创建 webview,但总是得到 404 错误作为响应。代码(没有令牌和回调网址):

import requests
from json import loads, dumps
from urllib.parse import quote_plus as urlencode

API_URL = "https://api.gupshup.io/sm/api/"

fields = [{
        "type": "input",
        "name": "curr_time",
        "label": "Enter time"
    }, {
        "type": "input",
        "name": "name",
        "label": "Apartment address"
    }]

headers = {
    'Content-Type': 'application/x-www-form-urlencoded',
    'Accept': 'text/plain',
    'apikey': 'my_token',
}

data = {
    "title": 'Create apartment',
    "autoClose": True,
    "message": 'Apartment created!',
    "callback-url": 'https://mycallback_url',
    "fields": fields,
    "users": ['My first form']
}

data = dumps(data)
data = 'formJSON=' + urlencode(data)

r = requests.post(API_URL + "facebook/smartmsg/form/create", data=data, headers=headers)

print(r)
print(r.content)
print(r.text)

当我尝试从标头中删除 apitoken 时,它给了我“401 未经授权。请传递 API 密钥”

文档:https ://www.gupshup.io/developer/docs/bot-platform/guide/serverless-webviews-using-gupshup

和在线api:https ://www.gupshup.io/developer/ent-apis

4

1 回答 1

2

将您的标题更改为以下之一,它应该开始工作

headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json',
'apikey': 'Your_apikey'
}

或者

headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'apikey': 'Your_apikey'
}
于 2017-08-16T06:53:21.223 回答