我正在遵循本文档,以在Gmail ID中获得用户的姓名。 我没有授权窗口来验证Gmail帐户。 https://developers.google.com/people
我提供了客户端ID和密钥。
有人可以告诉我这是怎么回事吗?
from django.shortcuts import render
from inviteapp.forms import InviteForm
import httplib2
from django.http import HttpResponse,HttpResponseRedirect
from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.tools import run_flow
def index(request):
if(request.method=="POST"):
email=''
invite=InviteForm(data=request.POST)
if invite.is_valid():
email=invite.cleaned_data['email']
# Set up a Flow object to be used if we need to authenticate. This
# sample uses OAuth 2.0, and we set up the OAuth2WebServerFlow with
# the information it needs to authenticate. Note that it is called
# the Web Server Flow, but it can also handle the flow for
# installed applications.
#
# Go to the Google API Console, open your application's
# credentials page, and copy the client ID and client secret.
# Then paste them into the following code.
FLOW = OAuth2WebServerFlow(
client_id='xxxx',
client_secret='xxx',
scope='https://www.googleapis.com/auth/contacts.readonly',
user_agent='xxx')
# If the Credentials don't exist or are invalid, run through the
# installed application flow. The Storage object will ensure that,
# if successful, the good Credentials will get written back to a
# file.
storage = Storage('info.dat')
credentials = storage.get()
if credentials is None or credentials.invalid == True:
credentials = run_flow(FLOW, storage)
# Create an httplib2.Http object to handle our HTTP requests and
# authorize it with our good Credentials.
http = httplib2.Http()
http = credentials.authorize(http)
# Build a service object for interacting with the API. To get an API key for
# your application, visit the Google API Console
# and look at your application's credentials page.
people_service = build(serviceName='people', version='v1', http=http)
profile = people_service.people().get(email, personFields='names,emailAddresses')
print('here',profile)
return HttpResponse('thanks')
return render(request,"index.html",{'form':InviteForm()})
这是错误
[01/Jun/2020 15:27:13] "GET /invite/ HTTP/1.1" 200 817
C:\Users\hp\Desktop\django\venv\lib\site-packages\oauth2client\_helpers.py:255: UserWarning: Cannot access info.dat: No such file or directory
warnings.warn(_MISSING_FILE_MESSAGE.format(filename))
usage: manage.py [--auth_host_name AUTH_HOST_NAME] [--noauth_local_webserver]
[--auth_host_port [AUTH_HOST_PORT [AUTH_HOST_PORT ...]]]
[--logging_level {DEBUG,INFO,WARNING,ERROR,CRITICAL}]
manage.py: error: unrecognized arguments: runserver
Traceback (most recent call last):
File "c:\users\hp\appdata\local\programs\python\python36\lib\wsgiref\handlers.py", manage.py: error: unrecognized arguments: runserver
Traceback (most recent call last):
File "c:\users\hp\appdata\local\programs\python\python36\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Users\hp\Desktop\django\venv\lib\site-packages\django\contrib\staticfiles\handlers.py", line 68, in __call__
return self.application(environ, start_response)
File "C:\Users\hp\Desktop\django\venv\lib\site-packages\django\core\handlers\wsgi.py", line 133, in __call__
response = self.get_response(request)
File "C:\Users\hp\Desktop\django\venv\lib\site-packages\django\core\handlers\base.py", line 75, in get_response
response = self._middleware_chain(request)
File "C:\Users\hp\Desktop\django\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\hp\Desktop\django\venv\lib\site-packages\django\utils\deprecation.py", line 94, in __call__
response = response or self.get_response(request)
File "C:\Users\hp\Desktop\django\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\hp\Desktop\django\venv\lib\site-packages\django\utils\deprecation.py", line 94, in __call__
response = response or self.get_response(request)
File "C:\Users\hp\Desktop\django\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\hp\Desktop\django\venv\lib\site-packages\django\utils\deprecation.py", line 94, in __call__
response = response or self.get_response(request)
File "C:\Users\hp\Desktop\django\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\hp\Desktop\django\venv\lib\site-packages\django\utils\deprecation.py", line 94, in __call__
response = response or self.get_response(request)
File "C:\Users\hp\Desktop\django\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\hp\Desktop\django\venv\lib\site-packages\django\utils\deprecation.py", line 94, in __call__
response = response or self.get_response(request)
File "C:\Users\hp\Desktop\django\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\hp\Desktop\django\venv\lib\site-packages\django\utils\deprecation.py", line 94, in __call__
response = response or self.get_response(request)
File "C:\Users\hp\Desktop\django\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\hp\Desktop\django\venv\lib\site-packages\django\utils\deprecation.py", line 94, in __call__
response = response or self.get_response(request)
File "C:\Users\hp\Desktop\django\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\hp\Desktop\django\venv\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\hp\Desktop\django\invite\inviteapp\views.py", line 38, in index
credentials = run_flow(FLOW, storage)
File "C:\Users\hp\Desktop\django\venv\lib\site-packages\oauth2client\_helpers.py", line 133, in positional_wrapper
return wrapped(*args, **kwargs)
File "C:\Users\hp\Desktop\django\venv\lib\site-packages\oauth2client\tools.py", line 194, in run_flow
flags = argparser.parse_args()
File "c:\users\hp\appdata\local\programs\python\python36\lib\argparse.py", line 1737, in parse_args
self.error(msg % ' '.join(argv))
File "c:\users\hp\appdata\local\programs\python\python36\lib\argparse.py", line 2393, in error
self.exit(2, _('%(prog)s: error: %(message)s\n') % args)
File "c:\users\hp\appdata\local\programs\python\python36\lib\argparse.py", line 2380, in exit
_sys.exit(status)
SystemExit: 2
[01/Jun/2020 16:15:11] "POST /invite/ HTTP/1.1" 500 59
我的HTML表单页面显示此消息
发生服务器错误。请与管理员联系。