簡體   English   中英

使用Python + urlfetch向GAE中的Github API發出經過身份驗證的請求

[英]Making an authenticated request to the Github API in GAE using Python + urlfetch

使用Python和urlfetch在GAE中獲得訪問令牌后,如何向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 / 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,
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM