2015-07-13 61 views
0

我需要登錄扔我的網頁谷歌。我得到了我的clientID並在Google Console中設置了redirect_uri路徑,但是當我嘗試登錄時,它給了我以下錯誤。我正在將其整合到我的asp.net頁面上。redirect_uri_mismatch錯誤的谷歌API,同時嘗試登錄使用C#asp.net

Error: 400. That’s an error.
Error: redirect_uri_mismatch
Application: odiyaDoctor
You can email the developer of this application at: [email protected]
The redirect URI in the request: http://localhost/immediateHelp.aspx did not match a registered redirect URI.

我的要求是,當用戶由谷歌第一頁(UserLogin.aspx)上,併成功登錄下一個頁面(i.e.immediateHelp.aspx)會後登錄。我在下面解釋我的所有代碼和Google憑據。

UserLogin.aspx:

<a href="#" class="btn btn-large btn-block btn-google" onclick="googleLogin();" >Login with Google <i class="fa fa-google-plus"></i></a> 
<script> 
    var OAUTHURL = 'https://accounts.google.com/o/oauth2/auth?'; 
    var VALIDURL = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token='; 
    var SCOPE = 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email'; 
    var CLIENTID = '*************************g96b1elfa8.apps.googleusercontent.com'; 
    var REDIRECT = 'http://localhost/immediateHelp.aspx'; 
    var LOGOUT = 'http://accounts.google.com/Logout'; 
    var TYPE = 'token'; 
    var _url = OAUTHURL + 'scope=' + SCOPE + '&client_id=' + CLIENTID + '&redirect_uri=' + REDIRECT + '&response_type=' + TYPE; 
    var acToken; 
    var tokenType; 
    var expiresIn; 
    var user; 
    var loggedIn = false; 
    function googleLogin() { 
     var win = window.open(_url, "windowname1", 'width=800, height=600'); 
     var pollTimer = window.setInterval(function() { 
      try { 
       console.log(win.document.URL); 
       if (win.document.URL.indexOf(REDIRECT) != -1) { 
        window.clearInterval(pollTimer); 
        var url = win.document.URL; 
        acToken = gup(url, 'access_token'); 
        tokenType = gup(url, 'token_type'); 
        expiresIn = gup(url, 'expires_in'); 
        win.close(); 
        validateToken(acToken); 
       } 
      } catch (e) { 
       console.log('its error', e); 
      } 
     }, 500); 
    } 
    function validateToken(token) { 
     $.ajax({ 
      url: VALIDURL + token, 
      data: null, 
      success: function (responseText) { 
       getUserInfo(); 
       loggedIn = true; 
       window.location.href = "immediateHelp.aspx"; 
      }, 
      dataType: "jsonp" 
     }); 
    } 
    function getUserInfo() { 
     $.ajax({ 
      url: 'https://www.googleapis.com/oauth2/v1/userinfo?access_token=' + acToken, 
      data: null, 
      success: function (resp) { 
       user = resp; 
       console.log('user info',user); 
       $('#imgHolder').attr('src', user.picture); 
      }, 
      dataType: "jsonp" 
     }); 
    } 
    function gup(url, name) { 
     name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); 
     var regexS = "[\\#&]" + name + "=([^&#]*)"; 
     var regex = new RegExp(regexS); 
     var results = regex.exec(url); 
     if (results == null) 
      return ""; 
     else 
      return results[1]; 
    } 
</script> 

在波紋管誤差在閉鎖段即將上述頁面。 Web應用

at http://localhost:3440/UserLogin.aspx:92:32 UserLogin.aspx:103 its error DOMException: Blocked a frame with origin " http://localhost:3440 " from accessing a cross-origin frame. at Error (native)

clientID set in google.

客戶端ID

Client ID 
***************************************1ctsjaeg96b1elfa8.apps.googleusercontent.com 
Client secret 
*********oGbT13hv3S 
Redirect URIs 
https://localhost/immediateHelp.aspx 
JavaScript origins 
https://localhost 

在這裏,我需要在用戶成功登錄,它會重定向到immediateHelp.aspx頁面,該頁面中,用戶可以做logout.Please幫我解決這些錯誤。

+0

在谷歌開發者控制檯,您需要添加http://localhost/immediateHelp.aspx作爲重定向URI – DaImTo

+0

@ Dalm要:我在上面已經加入後。檢查。 – satya

+0

「請求中的重定向URI:http://localhost/immediateHelp.aspx與註冊的重定向URI不匹配。」谷歌並不說謊,你沒有它。 – DaImTo

回答

0
`"http://localhost/immediateHelp.aspx" != "https://localhost/immediateHelp.aspx" 

的URL必須是性格完美

+0

whats about第二個錯誤。如何解決。 – satya

+0

第二個錯誤?這是StackOverflow。每個線程有一個問題。 – pinoyyid

相關問題