使用OAuth身份驗證方法時,我無法從url中檢索身份驗證代碼。谷歌重定向我的代碼的URL附加到其結束Django Google API Client Error..Trying實現應用程序,在認證後向用戶的Google日曆中添加事件
..我想我是因爲自己的身份驗證,並給予應用程序來管理我的日曆我重定向到 http://127.0.0.1/Main/addloanpremium/?code=4/2wi1hu0Gv8YZuKo79kc-kjCmw7qj0W2EyLYa3qzIe7w#許可後進行的正則表達式錯誤..我如何從網址中提取代碼..上面的網址在新標籤頁上打開,並且由於我的urls.py顯示了相同的表單頁面,但是當我嘗試訪問使用request.GET.get('代碼「),它並沒有給任何價值..
異常值:無法將‘NoneType’對象爲str隱含
我views.py看起來像:
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',{})
我公司主營:urls.py:
url(r'^addloanpremium/$',views.addloanpremium,name='addloanpremium'),
我loan_pre_form.html包含
<form action=" {% url 'Main:addloanpremium' %}" method="GET">
任何幫助將高度讚賞。