2014-10-30 5 views
3

내가 Google's developer tutorial
에서 샘플 예를 따르도록 노력하고 업데이트하여 크롬 (버전 38.0)gapi.auth 자바 스크립트 명령이 제대로

을 실행하지만 도달 결코 gapi.auth 기능처럼 보인다되지 않습니다 자신의 콜백 여기

그것을 증명하는 코드 예제 :

<!doctype html> 
<html> 
    <head> 
    <title>Google API Client test</title> 
    </head> 
    <body> 
    here will be the use of Oauth 2.0 
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> 
    <script>  
    googleApiClientReady = function() {  
    window.setTimeout(checkAuth, 1); 
    } 
    function checkAuth() {  
     gapi.auth.authorize({ 
    client_id: 'XXX', 
    scope: 'https://www.googleapis.com/auth/youtube', 
    immediate: true 
    }, handleAuthResult); 
    } 
    function handleAuthResult(authResult) { 
    if (authResult && !authResult.error) { 
    alert('gapi.auth return successfully'); 
    } else { 
    alert('gapi.auth return with error'); 
    } 
    } 
    </script> 
    <script src="https://apis.google.com/js/client.js?onload=googleApiClientReady"></script> 
    </body> 
</html> 

나는 위의 HTML을 실행 + JS는 'HandleAuthResult'의 2 옵션의 경고 없음 모든에서 화면 에 표시되는 파일 - 때 -이 기능이 'gapi.auth.authorize'

에 의해 다시 호출되지 않습니다 것을 의미한다

누구든지이 라이브러리를 제대로 사용할 수 있습니까?

답변

0

먼저 크롬이 팝업을 차단했는지 확인해야합니다. 이는 팝업창 열기 코드가 온 클릭 처리기에 없기 때문입니다.

그러면 Chrome의 개발자 콘솔을 열고 '콘솔'탭에서 오류를 확인해야합니다. "나는 만 제거한 후 코드를 사용하여 성공적으로 콜백 를 구글에 로그인받을 수 있었다 Google developer console - javascript origins

:

또한 당신은 당신의 페이지가 다음과 같이 구글 개발자 콘솔에 위치한 도메인 이름과 포트를 지정해야합니다 즉각적인 : 참 "옵션. 이유는 모르겠지만 "immediate_failed"오류가 발생했습니다.

+0

http://stackoverflow.com/questions/21710842/google-api-in-javascript – GyRo

+0

감사합니다. 이것은 도움이되었다. 또한 웹 서버 (http 시작 URL)에서 html을 실행하고 파일 시스템을 통해 직접 실행하지 않은 경우에만 작동했습니다. – GyRo

관련 문제