【发布时间】:2015-09-04 11:46:39
【问题描述】:
有一个python应用使用Health Graph API
# -*- coding: utf-8 -*-
from django.shortcuts import render_to_response, redirect
from main.settings import CLIENT_ID, CLIENT_SECRET, RUNKEEPER_LOGIN_URL, ACCESS_TOKEN_URL
import requests
def index(request):
return render_to_response('index.html')
def login(request):
code = request.GET['code']
post_data = {'grant_type': 'authorization_code',
'code': code,
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET,
'redirect_uri': 'http://127.0.0.1:8000/welcome/'}
req = requests.post(ACCESS_TOKEN_URL, data=post_data)
我的登录按钮将用户重定向到 Health Graph 登录页面,让我的应用等待授权码。
<a href="https://runkeeper.com/apps/authorize?redirect_uri=http%3A%2F%2F127.0.0.1%3A8000%2Flogin&response_type=code&client_id=xxxxxxxxx">
当我尝试通过调用登录函数获取访问令牌时,我收到“无效授权”错误作为请求。我试图将“authorization_code”替换为另一个词,但出现了另一个“不支持的授权类型”错误。换句话说,令牌服务器拒绝我从身份验证服务器获得的代码。我做错了什么?
【问题讨论】:
标签: python python-2.7 oauth oauth-2.0