【问题标题】:Gupshup can't send request to create webviewGupshup 无法发送创建 webview 的请求
【发布时间】:2018-01-20 05:40:01
【问题描述】:

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

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 Unauthorized. Please pass the API key”

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

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

【问题讨论】:

    标签: python api python-requests http-status-code-404 gupshup


    【解决方案1】:

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

    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'
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-30
      • 2011-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-10
      相关资源
      最近更新 更多