如何使用 Discourse API 获取当前用户
How to get current user with Discourse API
我正在访问 Discourse API from python using urlfetch。 通过用户名获取单个用户 端点需要 GET 请求,例如 /users/{username}.json
从浏览器中,此命令 returns 按预期得到 json 响应,但是来自 API 调用,如:
from google.appengine.api import urlfetch
result = urlfetch.fetch('{}/users/{}.json'.format(domain, username))
它 returns 一个 HTML 页面。我什至尝试将内容类型设置为 application/json:
headers = {'Content-Type': 'application/json'}
result = urlfetch.fetch('{}/users/{}.json'.format(domain, username), headers=headers)
我做错了什么?
已解决:
需要在 GET 请求中添加 api_key 和 api_username:
result = urlfetch.fetch('{}/users/{}.json?api_key={}&api_username={}'.format(domain, username, discourse_api_key, discourse_api_username))
我正在访问 Discourse API from python using urlfetch。 通过用户名获取单个用户 端点需要 GET 请求,例如 /users/{username}.json
从浏览器中,此命令 returns 按预期得到 json 响应,但是来自 API 调用,如:
from google.appengine.api import urlfetch
result = urlfetch.fetch('{}/users/{}.json'.format(domain, username))
它 returns 一个 HTML 页面。我什至尝试将内容类型设置为 application/json:
headers = {'Content-Type': 'application/json'}
result = urlfetch.fetch('{}/users/{}.json'.format(domain, username), headers=headers)
我做错了什么?
已解决:
需要在 GET 请求中添加 api_key 和 api_username:
result = urlfetch.fetch('{}/users/{}.json?api_key={}&api_username={}'.format(domain, username, discourse_api_key, discourse_api_username))