So I have this code with which to connect to Google API and get some user information. The problem is that people who start the login function do not work.
This is a Java practice project, which has been created by Maven and posted on the Tomcat server, if it helps.
& lt ;! DOCTYPE html & gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; Script src = 'http: //code.jquery.com/jquery-2.1.3.min.js'> & Lt; / Script & gt; & Lt; Script type = 'text / javascipt' & gt; $ (Document) .ready (function () {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 =' SAARC '; Var REDIRECT = 'myredirect'; var LOGOUT = 'http://accounts.google.com/Logout'; var TYPE = 'token'; var url1 = OAUTHURL + 'scope =' + SCOPE + 'and client_id =' + CLIENTID + 'And amp; redirect_uri =' + REDIRECT + 'and response_type =' + TYPE; var acToken; var ends of token type var; var user; var login = function; function login () {var win = Window.open (url1, 'Windowname1', 'width = 800, height = 600'); var pollTimer = window.setInterval (Function () {try {console.log (win.document.URL); if (win.document.URL.indexOf (radrite)! = -1) {window.clearInterval (pollTimer); var url = win.document URL; AcToken = gup (url, 'access_token'); TokenType = gup (url, 'token_type'); Ends = gup (url, 'expires_in'); Win.close (); ValidateToken (acToken); }} Catch (e) {}}, 500); }); Validate the function token (token) {$. Ajax ({url: VALIDURL} token, data: blank, success: function (feedback lesson) {getUserInfo (); login = true; $ ('# login text') Hide (); $ ('# logout text' ). Show ();}, Datatype: 'jsonp'}); } GetUserInfo () function {$. Ajax ({url: 'https://www.googleapis.com/oauth2/v1/userinfo?access_token=' + acToken, data: empty, success: function} {user = resp $ ('# ughhoulder'). Et ('src', user.picture);}, datatype: 'jsonp'}); } / * Credit: http://www.netlobo.com/url_query_string_javascript.html*/function gup (url, name) {name = name.replace (/ [\\\\ [/], '\\\ [' ).To change(/[\]]/,'\\\]'); Var regexS = '[\\ # and amp;]' + name + '= ([^ & amp; #] *)'; Var rigax = new regexS; Var result = regex.exec (url); If return (result === blank); Results return [1]; } Function startLogoutPolling () {$ ('# Login Text'). Show (); Hide $ ('# LogoutText'). LoggedIn = false; $ ('# UName') Text ('Welcome'); $ ('# ImgHolder') Et ('src', 'none.jpg'); }}); & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; A href = "#" onclick = 'login ()' id = 'login text' & gt; Click here to login & lt; / A & gt; & Lt; A href = "#" style = 'display: none' id = 'logout text' target = 'myframe' onclick = "myIFrame.location = 'https: //www.google.com/accounts/Logout'; startLogoutPolling ( ); Return false; "& gt; Click here to logout & lt; / A & gt; & Lt; Iframe name = 'myiframe' id = 'myiframe' style = 'display: none' & gt; & Lt; / Iframe & gt; & Lt; Div id = 'uName' & gt; & Lt; / Div & gt; & Lt; Img src = '' id = 'imgholder' / & gt; & Lt; / Body & gt; & Lt; / Html & gt;
A small error, Big waste of time :)
& lt; Script type = 'text / javascript' & gt;
You've missed 'R' in javascipt
No comments:
Post a Comment