11

尝试运行我的应用程序时出现此错误...

The redirect URI in the request: http://localhost:8080/oauth2callback did not match a registered redirect URI

在 google API 控制台中,我已经注册了我的重定向网址

Redirect URIs:  http://localhost:8080/

在 client_secrets.json 中,我也使用与重定向 url 相同的链接,我正在关注本教程 https://developers.google.com/bigquery/articles/dashboard#addoauth2

编辑:

我只是对现有代码进行了一些更改

现在

redirect URIs in API console is     http://localhost:8080/oauth2callback

这是我的 app.yaml

application: hellomydashboard
version: 1
runtime: python
api_version: 1

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: /oauth2callback
  script: oauth2client/appengine.py

- url: .*
  script: main.py

现在虽然它没有显示任何错误,但它显示一个空白页。

这是我的 main.py

from bqclient import BigQueryClient
import httplib2
import os
from google.appengine.api import memcache
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from oauth2client.appengine import oauth2decorator_from_clientsecrets

# Project ID for project to receive bill.
# During limited availability preview, there is no bill.
# The value should be your quoted Client ID number 
# which you previously recorded from code.google.com/apis/console

# REPLACE THIS NUMBER WITH YOUR CLIENT ID
PROJECT_ID = "My Project ID"  #i just replaced dat
DATASET = "samples"
TABLE = "natality"

# CLIENT_SECRETS, name of a file containing the OAuth 2.0
# information for this application.
CLIENT_SECRETS = os.path.join(os.path.dirname(__file__),
    'client_secrets.json')

http = httplib2.Http(memcache)
decorator = oauth2decorator_from_clientsecrets(CLIENT_SECRETS,
    'https://www.googleapis.com/auth/bigquery')

bq = BigQueryClient(http, decorator)

class MainHandler(webapp.RequestHandler):
    @decorator.oauth_required
    def get(self):
        self.response.out.write("Hello Dashboard!\n")


application = webapp.WSGIApplication([
   ('/', MainHandler),
], debug=True)

def main():
   run_wsgi_app(application)

if __name__ == '__main__':
    main()

因此,根据 main.py,如果一切正常,它必须打印 Hello Dashboard 但事实并非如此

4

5 回答 5

19

您实际上需要将以下内容添加到重定向 URI:

http://localhost:8080/oauth2callback

/此外,如果上述内容不匹配,您可能需要附加尾随:

http://localhost:8080/oauth2callback/
于 2012-11-04T19:25:24.673 回答
3

使用谷歌 openId 我配置了这个

重定向 URI: http ://domain.com/authenticate/google

https://code.google.com/apis/console上,如果您没有应用,则必须创建应用,请注意必须与 url 完全匹配

于 2013-07-10T22:20:12.353 回答
1

在 main.py 函数中,主类添加(decorator.callback_path, decorator.callback_handler()),和删除

- url: /oauth2callback 
    script: oauth2client/appengine.py 

来自 app.yaml。

PS:如果你有一些代理配置/webcontent-filter,你可能会得到 DownloadError。如果您禁用这些配置或将其部署在 Google Server 上,它将正常工作。

于 2012-11-22T05:38:28.510 回答
1

当我尝试使用/Authorize/authorize时,似乎谷歌试图将 url 与区分大小写的原因相匹配,它给了我redirect_uri_mismatch第一个错误但对后一个有效

有人试着让我知道我是否错了

于 2013-06-19T13:27:25.363 回答
0

In main.py file,

in the part where you create a wsgi application

under application = webapp.wsgiapplication(

add a handler

(decorator.callback_path,decorator.callback_handler()),
于 2013-06-11T07:07:40.207 回答