Django Google API客户端错误..正在尝试实现一个在身份验证后向用户Google日历添加事件的应用程序
使用OAuth身份验证方法时,我无法从url检索身份验证代码。谷歌将我重定向到一个url,并在其末尾附加代码 …我认为我在正则表达式中犯了一个错误,因为在对自己进行身份验证并授予应用程序管理日历的权限后,我被重定向到了 ..如何从url中提取代码..上面的url在新选项卡上打开,由于我的url.py显示相同的表单页,但是当我尝试使用request.GET.GET('code')访问“code”值时,它不提供任何值 异常值:无法将“非类型”对象隐式转换为str My views.py看起来像:Django Google API客户端错误..正在尝试实现一个在身份验证后向用户Google日历添加事件的应用程序,django,oauth-2.0,google-calendar-api,google-oauth,google-client-login,Django,Oauth 2.0,Google Calendar Api,Google Oauth,Google Client Login,使用OAuth身份验证方法时,我无法从url检索身份验证代码。谷歌将我重定向到一个url,并在其末尾附加代码 …我认为我在正则表达式中犯了一个错误,因为在对自己进行身份验证并授予应用程序管理日历的权限后,我被重定向到了 ..如何从url中提取代码..上面的url在新选项卡上打开,由于我的url.py显示相同的表单页,但是当我尝试使用request.GET.GET('code')访问“code”值时,它不提供任何值 异常值:无法将“非类型”对象隐式转换为str My views.py看起来像: d
def addloanpremium(request):
if request.method == 'GET':
loan=Loan()
premium=Premium()
user=request.user
#form=loan_pre_form(request.POST)
if(request.GET.get('typelp')=='loan'):
loan.user=user
#premium.user=user
#lots of code here..all values from fields are stored into the db
if(request.GET.get("iscalendar")=="True"):
print(" \n \n entered iscalendar =true \n")
print(" \n \n entered calendar now trying to add event \n \n")
SCOPES = 'https://www.googleapis.com/auth/calendar'
flow=auth2client.client.flow_from_clientsecrets('C:/Users/ghw/Desktop/Expenze/Main/client_secrets.json',SCOPES,redirect_uri='http://127.0.0.1:8000/Main/addloanpremium/')
storage = oauth2client.file.Storage('credentials.dat')
credentials = storage.get()
if not credentials or credentials.invalid:
auth_uri = flow.step1_get_authorize_url()
print("\n value of auth uri is "+auth_uri+"\n")
webbrowser.open(auth_uri)
auth_code = request.GET.get('code')
print("\n value of auth code is "+auth_code+"\n")
### I am getting the auth code wrong
credentials = flow.step2_exchange(auth_code)
storage.put(credentials)
http = httplib2.Http()
http = credentials.authorize(http)
CAL = build('calendar', 'v3', http=http)
.
.#lots of code here
.
return render(request,'Main/loan_pre_form.html',{})
我的主页:url.py:
url(r'^addloanpremium/$',views.addloanpremium,name='addloanpremium'),
my loan_pre_form.html包含
<form action=" {% url 'Main:addloanpremium' %}" method="GET">
非常感谢您的帮助。基于此,函数将返回一个值,如果您不指定一个值,它将隐式返回None
异常值:无法将'NoneType'对象隐式转换为str错误意味着您试图将NoneType
用作字符串。我想问题是这个函数没有返回任何东西(在一种情况下),所以它实际上返回NoneType
这是一个来自谷歌文档的例子
您还可以检查这些相关线程: