2012-06-12 11 views
18

buon pic da Tim Rosenberg che mostra esattamente come OAuth2 il lavoro di:Fusiontables tavolo privato con OAuth2

enter image description here

Sono un po 'un pigro per iniziare anche a guardare questo 2files e test così ho cercato easyest modo per

1.Get gettone

2.accesso con quella pedina

con l'aiuto di gwt-oauth2

messo in testa index.php: <script type="text/javascript" src="gwt-oauth2.js"></script>

e questo nel corpo

<script type="text/javascript"> 
(function() { 
var GOOGLE_AUTH_URL = "https://accounts.google.com/o/oauth2/auth"; 
var GOOGLE_CLIENT_ID = "CLIENT_ID"; 
//var PLUS_ME_SCOPE = "https://www.googleapis.com/auth/plus.me"; 
//var FusionTable_SCOPE = "https://www.googleapis.com/auth/fusiontables";  
var button = document.createElement("button"); 
button.innerText = "Authenticate with Google"; 
button.onclick = function() { 

var req = { 
    'authUrl' : GOOGLE_AUTH_URL, 
    'clientId' : GOOGLE_CLIENT_ID, 
    'scopes': ['https://www.googleapis.com/auth/plus.me', 
       'https://www.googleapis.com/auth/fusiontables' 
       ], 
}; 

oauth2.login(req, function(token) { 
    alert('Got an OAuth token:\n'+ token +'\n'+ 'Token expires in '+ oauth2.expiresIn(req) +' ms\n'); 
    }, function(error) { 
    alert("Error:\n" + error); 
    }); 
}; 

var dv = document.getElementById('admin-content'); 
dv.appendChild(button); 
var clearTokens = document.createElement('button'); 
clearTokens.innerText = 'Clear all tokens' 
clearTokens.onclick = oauth2.clearAllTokens; 
dv.appendChild(clearTokens); 
})(); 
</script> 

OK,

Ora è possibile vedere il collegamento e il reindirizzamento a oauthWindow.html in una nuova finestra senza errori. I parametri GET ora ti mostrano access_tokentoken_typeexpires_in. Controllare il access_token HERE

Come vedete access_token lavoro grande, ma

Quello che ancora non si ottiene è il primo avviso da quella:

oauth2.login(req, function(token) { 
    alert('Got an OAuth token:\n' + token + '\n' 
    + 'Token expires in ' + oauth2.expiresIn(req) + ' ms\n'); 
}, function(error) { 
    alert("Error:\n" + error); 
}); 

secondo avviso funziona bene e quando si tenta di Auth. ancora una volta se oauthWindow.html aprire ancora vi mostra un avviso di errore (in modo che tutto funzioni!) Ora aggiungiamo quel piccolo codice per oauthWindow.html

<!DOCTYPE html> 
<html> 
    <head> 
    <script type="text/javascript"> 
     if (window.opener && window.opener.oauth2 && window.opener.oauth2.__doLogin) { 
     window.opener.oauth2.__doLogin(location.hash); 
     } else { 
     document.body.innerText = "Your browser seems to be stopping this window from communicating with the main window."; 
     } 
    </script> 
    </head> 
    <body></body> 
</html> 

Perfetto!

Ora se si desidera lavorare con tabelle private tutto ciò che serve è aggiungere un access_token all'URL.

Grazie per avermi dato il motivo per rispondermi!

+0

Grazie signore. Grazie mille. – efwjames

+6

perché hai eliminato la risposta? È necessario ripristinarlo e quindi fare clic sul pulsante Accetta. Ciò dovrebbe aiutare gli utenti che cercano una soluzione simile. –

+0

@Joseph Marikle mio errore. risolto. – qpaycm

risposta

1

mettere questo in oauthWindow.html file di

<!DOCTYPE html> 
<html> 
    <head> 
    <script type="text/javascript"> 
     if (window.opener && window.opener.oauth2 && window.opener.oauth2.__doLogin) { 
     window.opener.oauth2.__doLogin(location.hash); 
     } else { 
     document.body.innerText = "Your browser seems to be stopping this window from communicating with the main window."; 
     } 
    </script> 
    </head> 
    <body></body> 
</html>