Survey Monkey API-获取长期访问令牌

时间:2017-02-22 17:08:45

标签: api oauth api-design surveymonkey alteryx

我目前无法弄清楚如何获取我的长期访问令牌,因此我可以创建从Survey Monkey到Alteryx的API数据源。

到目前为止,我已经能够:

1)转到OAUTH页面 https://api.surveymonkey.net/oauth/authorize?redirect_uri = https:// www.surveymonkey.com& client_id = [MY-CLIENT-ID]& response_type = code

2)验证访问权限(我不是机器人:reCAPTCHA)

3)使用短期代码获取身份验证响应 https:// www。 surveymonkey.com/home/?code=[CODE-FROM-RESPONSE]

4)卡住了

来自:https://developer.surveymonkey.com/docs/guides/oauth-guide/

要进行交换,只需使用以下编码表单字段创建一个表单编码(Content-Type:application / x-www-form-urlencoded)HTTP POST请求到https://api.surveymonkey.net/oauth/token?api_key=YOUR_API_KEY:client_secret, code,redirect_uri和grant_type。授权类型必须设置为" authorization_code"。

这不是简单的"对我来说,并且非常感谢表达式,所以我可以将其输入浏览器,以便我可以检索我的长期访问令牌。

最终目标是我使用Alteryx通过API提取Survey Monkey数据并使用其他系统数据创建混合数据集。然后,组合数据集将提供Tableau Dashboard。我确信它是一个长镜头,但是如果有人有一个用于Survey Monkey API的Alteryx工作流程,它可以立即解决我的所有问题。

提前感谢您的见解/指导。

感激, 德鲁

(注意 - 我在一些链接中添加了空格,因为我没有10个声望点;但是)。

1 个答案:

答案 0 :(得分:1)

文档here旁边有一个示例cURL请求。您需要向/oauth/token发出POST请求。它看起来像这样:

curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d 'code=<code>&client_id=<client_id>&client_secret=<client_secret>&redirect_uri=<redirect_uri>&grant_type=authorization_code' "https://api.surveymonkey.net/oauth/token"

填写<>中的值。或者在Python中,这样的东西应该有效:

import requests

url = "https://api.surveymonkey.net/oauth/token"

payload = {
    "code": "<code>",
    "client_id": "<client_id>",
    "client_secret": "<client_secret>",
    "redirect_uri": "<redirect_uri>",
    "grant_type": "authorization_code"
}

headers = {
    'content-type': "application/x-www-form-urlencoded"
}

response = requests.request("POST", url, data=payload, headers=headers)

我很确定请求库会自动将正文转换为正确的类型,但如果不是有效负载,则看起来像URL参数:

payload = "code=<code>&client_id=<client_id>&client_secret=<client_secret>&redirect_uri=<redirect_uri>&grant_type=authorization_code"

基本上,您只需要使用上面提供的有效负载(code,client_id,client_secret,redirect_uri和grant_type)向/oauth/token发出POST请求。令人困惑的主要部分是你不能发送JSON主体,它必须是一个看起来像我上面例子的表单体。

希望有所帮助。