我在GAE中以應用程序身份驗證Github API時遇到問題(GAE在使用Github3時拋出異常)。在GAE上使用Python對Github API進行身份驗證
import os, sys
sys.path.append("lib")
import jinja2, webapp2, urllib
from google.appengine.api import users, oauth, urlfetch
JINJA_ENVIRONMENT = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
extensions=['jinja2.ext.autoescape'],
autoescape=True)
class ConsoleLogin(webapp2.RequestHandler):
def get(self):
google_user = users.get_current_user()
if google_user:
fields = {
"client_id" : os.environ.get('CLIENT_ID'),
"scope" : "user, repo"
}
url = 'https://github.com/login/oauth/authorize'
data = urllib.urlencode(fields)
result = urlfetch.fetch(url=url,
payload=data,
method=urlfetch.GET
)
在這段代碼之後,你應該從Github獲得一個臨時代碼。
問題:我根本找不到它。我在導遊裏看到你應該把它當作一個環境變量,但我看不到它。
幫助我完成Python腳本的人的額外要點。 ;)
完全可以在GAE上使用請求。而github3似乎只需要作爲一個依賴,所以它應該是兼容的。 –
但是令牌在'result'中,而不是環境變量。 –
嗨@DanielRoseman,每次我嘗試使用請求時,都會拋出一個奇怪的異常。你能寫出代碼從結果中獲取令牌嗎?這將是一個巨大的幫助。 – Ben