【问题标题】:Google App Engine oauth2 Callback 404Google App Engine oauth2 回调 404
【发布时间】:2017-06-12 10:19:57
【问题描述】:

点击谷歌驱动器的授权按钮后,我收到 404 资源未找到错误。我的代码如下 - 任何想法我做错了什么?

from __future__ import print_function
import httplib2
import os

from apiclient import discovery
from oauth2client import client
from oauth2client import tools
from oauth2client.file import Storage
from apiclient.discovery import build
from google.appengine.ext import webapp
from oauth2client.appengine import OAuth2DecoratorFromClientSecrets

import webapp2



try:
    import argparse
    flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
except ImportError:
    flags = None
except SystemExit:
    flags= None
#
## If modifying these scopes, delete your previously saved credentials
## at ~/.credentials/drive-python-quickstart.json
SCOPES = 'https://www.googleapis.com/auth/drive'
CLIENT_SECRET_FILE = 'client_secret.json'
APPLICATION_NAME = 'Drive API Quickstart'

decorator = OAuth2DecoratorFromClientSecrets( CLIENT_SECRET_FILE,SCOPES)

service = build('drive', 'v3')

class MainHandler(webapp.RequestHandler):

  @decorator.oauth_required
  def get(self):
    # Get the authorized Http object created by the decorator.
    http = decorator.http()
    # Call the service using the authorized Http object.
    request = service.files().list(q = "mimeType != 'application/vnd.google-apps.folder'", pageSize=1000,  )
    response = request.execute(http=http)
    
app = webapp.WSGIApplication([
    ('/', MainHandler),
], debug=True)

我有 https://drive-156701.appspot.com/oauth2callback 结尾有和没有 / 作为重定向,我认为正确的重定向网址在哪里? 谢谢!!

【问题讨论】:

    标签: google-app-engine oauth-2.0 google-api gcloud google-python-api


    【解决方案1】:

    您没有/oauth2callback 的 URL 处理程序。您只有/ 的 url 处理程序。试试:

    app = webapp.WSGIApplication([
        ('/oauth2callback', Oauth2CallbackHandler),
        ('/', MainHandler),
    ], debug=True)
    

    并创建一个Oauth2CallbackHandler 类来处理回调。

    【讨论】:

      【解决方案2】:

      除了包括:

      app = webapp2.WSGIApplication( [ ('/', MainHandler), (decorator.callback_path, decorator.callback_handler()), ], 调试=真)

      @decorator.oauth_required 为您处理回调。

      观看此视频:https://www.youtube.com/watch?v=HoUdWBzUZ-M 您需要为 localhost 开发和部署创建凭据。

      并确保您已签出:https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27 您的 api 导入必须像第 3 方导入一样处理,详情如下: https://developers.google.com/api-client-library/python/start/installation

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-09-09
        • 2014-09-23
        • 1970-01-01
        • 2010-09-16
        • 1970-01-01
        • 1970-01-01
        • 2018-08-10
        • 2011-07-18
        相关资源
        最近更新 更多