如何修复python中的“未找到:/ oauth2callback”错误

时间:2019-01-19 07:12:37

标签: python django gmail-api

I'm using Python and Django for accessing Gmail using Gmail API after authentication completed it is showing the following error Not Found: /oauth2callback

I'm using python 3.6, Django 2.0.7, google-api-python-client 1.7, oauth2client==4.1.2,  

from django.shortcuts import render

import pickle
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from oauth2client import client
from django.http import HttpResponseRedirect

SCOPES = 'https://mail.google.com/'
redirect_uri='http://127.0.0.1:8000/oauth2callback'

def accesmail(request):
      creds = None
      if os.path.exists('token.pickle'):
           with open('token.pickle', 'rb') as token:
               creds = pickle.load(token)
      if not creds or not creds.valid:
         if creds and creds.expired and creds.refresh_token:
             creds.refresh(Request())
         else:
            FLOW = client.flow_from_clientsecrets('credentials.json', SCOPES,redirect_uri)
            authorize_url = FLOW.step1_get_authorize_url()

            #with open('token.pickle', 'wb') as token:
            #    pickle.dump(creds, token)
      return HttpResponseRedirect(authorize_url)

我希望在身份验证完成后重定向到我自己的HTML页面,并访问Gmail收件箱消息,并且希望将凭据存储在数据库中

0 个答案:

没有答案