2013-06-05 111 views
0

我是App Engine的新手,並且正在嘗試編寫一個應用程序,該應用程序將訪問Google日曆以獲取當前任何事件的詳細信息。我正在努力查看身份驗證如何工作以允許訪問日曆。我相信了OAuth2是首選的身份驗證選項,所以我有一個從API Access項目我已分別創建了ClientID的和客戶端祕密的client_secrets.json文件:使用Google App Engine以日曆身份驗證

{ 
"web":{ 
"auth_uri":"https://accounts.google.com/o/oauth2/auth", 
"client_secret":"xxxxxxx", 
"token_uri":"https://accounts.google.com/o/oauth2/token", 
"client_email":"[email protected]", 
"redirect_uris":["https://myapp.appspot.com/oauth2callback"], 
"client_x509_cert_url":"https://www.googleapis.com/robot/v1/metadata/x509/[email protected]", 
"client_id":"123456789.apps.googleusercontent.com", 
"auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs", 
"javascript_origins":["https://myapp.appspot.com"] 
} 
} 

這是從API訪問項目的直接出口'下載JSON'選項。當我部署我的App Engine應用程序我得到一個錯誤:

Error: redirect_uri_mismatch 
The redirect URI in the request: http://myapp.appspot.com/oauth2callback did not match a registered redirect URI 
Learn more 
Request Details 
scope=https://www.googleapis.com/auth/calendar 
response_type=code 
access_type=offline 
redirect_uri=https://myapp.appspot.com/oauth2callback 
display=page 
client_id=123456789.apps.googleusercontent.com 

這一切看起來好像沒什麼問題,所以我不知道是什麼錯誤是告訴我。我需要以某種方式將App Engine應用程序鏈接到API Access項目。我是否缺少別的根本。

如果有任何其他信息可以幫助您瞭解設置,請告訴我。我想保持這個帖子小。

回答

1

有,說評論here

When you created your credentials, you probably indicated that the client credentials you were creating were for a web application instead of an installed application. When you do that, you enter a Redirect URI for that set of credentials. The sample you are using is using the out of band Redirect URI for installed applications which does not match the one you specified, so it will not allow you to compete the authentication flow. This is to protect you from malicious use of your client credentials. Open the APIs console and create a new client ID for "installed applications" instead of "web applications" and this should work.

你建立一個Web應用程序或安裝的應用程序?

+0

我正在嘗試設置運行在Google App Engine上的Web應用程序。 Web應用程序仍然有問題嗎?謝謝詹姆斯 – James