【问题标题】:Making an authenticated request to the Github API in GAE using Python + urlfetch使用 Python + urlfetch 在 GAE 中向 Github API 发出经过身份验证的请求
【发布时间】:2014-03-08 23:06:07
【问题描述】:

在 GAE 中使用 Python 和 urlfetch 获得访问令牌后,如何向 Github API 发出经过身份验证的请求?

到目前为止,这是我的代码:

# Make an authenticated GET request to the Github API
url = 'https://api.github.com/user'
fields = {
    "access_token" : access_token,
}
data = urllib.urlencode(fields)
result = urlfetch.fetch(
    url=url,
    payload=data,
    method=urlfetch.GET,
)

我得到的错误是:

{"message":"Requires authentication","documentation_url":"http://developer.github.com/v3"}

我做错了什么,我该如何解决这个问题,以便发出正确的经过身份验证的请求?

【问题讨论】:

    标签: python google-app-engine github urllib2 github-api


    【解决方案1】:

    解决这个问题的方法很简单,虽然我花了很长时间才找到它。

    以下是使用 Python/Urlfetch 向 Google App Engine 上的 Github 发出经过身份验证的请求的代码:

    # Make an authenticated request
    url = 'https://api.github.com/user?access_token=' + str(access_token)
    result = urlfetch.fetch(
        url=url,
        method=urlfetch.GET,
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-29
      • 2016-05-01
      • 2021-12-31
      • 2016-05-25
      • 1970-01-01
      相关资源
      最近更新 更多