【问题标题】:survey monkey api: authorization token was not provided error调查猴子 api:未提供授权令牌错误
【发布时间】:2016-09-21 20:20:16
【问题描述】:

我正在尝试使用调查猴子 API 从我们上周启动的一项调查中提取数据,但我不断收到错误消息。我已经在开发者门户中注册了一个应用程序。如 Survey Monkey OAuth 开发人员备忘单 (https://gist.github.com/api-admin/11302313) 中所述,我以这种格式“https://api.surveymonkey.com/oauth/authorize?response_type=code&redirect_uri=https%3A%2F%2Fapi.surveymonkey.com%2Fapi_console%2Foauth2callback&client_id=SurveyMonkeyApiConsole&api_key=u366xz3zv6s9jje5mm3495fk”添加了“OAuth 重定向 URL”。我还设置了范围并将应用状态标记为“公开”。

这是我调用 API 的代码。

import requests
url = "https://api.surveymonkey.net/v3/surveys/%s?api_key=%s" % (survey_id, YOUR_API_KEY)
s = requests.Session()
s.get(url).text

这是我得到的错误。

Out[41]: u'{"error": {"docs": "https://developer.surveymonkey.com/api/v3/#error-codes", "message": "The authorization token was not provided.", "id": "1010", "name": "Authorization Error", "http_status_code": 401}}'

使用 API 下载数据还需要做什么?我正在使用 SELECT 年度计划订阅。

【问题讨论】:

    标签: oauth surveymonkey


    【解决方案1】:

    您需要在标头中设置访问令牌。我刚刚检查了文档中的示例,并且缺少该示例。文档应该是固定的。

    OAuth 示例是here。因此,特别是对于该请求,您需要执行以下操作:

    headers = {
        'Content-Type': 'application/json',
        'Authorization': 'bearer ACCESS_TOKEN_HERE'
    }
    
    s.get(url, headers=headers)
    

    这应该适合你。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-17
      • 2019-07-07
      • 1970-01-01
      • 2020-07-13
      • 2012-07-20
      • 2021-12-09
      • 2023-03-03
      • 2018-01-31
      相关资源
      最近更新 更多