2012-12-18 4 views
-1

페이스 북의 로그인 도움말 가이드를 사용하여 사용자가 로그인했는지 확인하는 스크립트를 작성하려고합니다. this guide을 기반으로 다음을 작성했습니다.예기치 않은 토큰 오류

<div id="fb-root"></div> 
<script> 
    // Additional JS functions here 
    window.fbAsyncInit = function() { 
    FB.init({ 
     appId  : '303594953085775', // App ID 
     channelUrl : 'http://mysite.com/pages/account/channel.html', // Channel File 
     status  : true, // check login status 
     cookie  : true, // enable cookies to allow the server to access the session 
     xfbml  : true // parse XFBML 
    }); 

    // Additional init code here 
    FB.getLoginStatus(function(response) { 
    if (response.status === 'connected') { 
     // connected 
    } else if (response.status === 'not_authorized') { 
     // not_authorized 
     login(); 
    } else { 
     // not_logged_in 
     login(); 
    } 
    }); 
    }; 

    }; 

    function login() { 
    FB.login(function(response) { 
     if (response.authResponse) { 
      // connected 
      testAPI(); 
     } else { 
      // cancelled 
     } 
    }); 
    } 

    function testAPI() { 
    console.log('Welcome! Fetching your information.... '); 
    FB.api('/me', function(response) { 
     console.log('Good to see you, ' + response.name + '.'); 
    }); 
    } 

    // Load the SDK Asynchronously 
    (function(d){ 
    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
    if (d.getElementById(id)) {return;} 
    js = d.createElement('script'); js.id = id; js.async = true; 
    js.src = "//connect.facebook.net/en_US/all.js"; 
    ref.parentNode.insertBefore(js, ref); 
    }(document)); 
</script> 

내가 정확히 무엇을 잘못했는지는 알지 못합니다. 나는 그것을 4 번 복사했고, 그것이 정확하게인데도 불구하고 여전히 오류가 발생했습니다. 페이스 북 사이트에 쓰여진 내용입니다. 나는 기본적인 통화와 물건 몇 가지 작업을 수행하는 방법을 알고 난 정말 복잡한 자바 스크립트의이 종류에 대해 아무것도 몰라

Uncaught SyntaxError: Unexpected token }

Uncaught SyntaxError: Unexpected token .

:

나는 두 가지 오류를 얻을 수 이것은 현재 내가 건물에서 벗어나고 싶어하는 것입니다.

왜 오류가 발생했는지 알 수 있습니까? 어딘가에 나는이 바보 같은 페이 스북 가이드를 거치지 않고 정확한 스크립트 전체를 잡고 응용 프로그램 ID와 도메인을 대체 할 수 있습니까?

+1

잡히지 않습니까? SyntaxError 메시지에도 줄 번호와 문자 번호가 있습니까? 당신은 여분이있는 것처럼 보입니다}; 첫 번째 fbAsyncInit 함수 후 – TommyBs

+0

'if-else' 절을 다음과 같이 바꿀 수 있다는 것을 알고 있습니다 :'if (response.status! == 'connected') login();' – ifaour

+0

실제 앱 ID입니까? 공개 포럼에 게시하지 마십시오. –

답변

1

코드에서 구문 오류가 존재 :

window.fbAsyncInit = function() { 
    FB.init({ 
    appId  : '303594953085775', // App ID 
    channelUrl : 'http://mysite.com/pages/account/channel.html', // Channel File 
    status  : true, // check login status 
    cookie  : true, // enable cookies to allow the server to access the session 
    xfbml  : true // parse XFBML 
    }); 

    // Additional init code here 
    FB.getLoginStatus(function(response) { 
    if (response.status === 'connected') { 
     // connected 
    } else if (response.status === 'not_authorized') { 
     // not_authorized 
     login(); 
    } else { 
     // not_logged_in 
     login(); 
    } 
    }); 

}; 
};  **// REMOVE THIS- This one is extra** 

당신은 메모장을 사용할 수 있습니다 ++ 또는 다른 좋은 편집기 나 복사에 의해 발생 된이 같은 문제가 없었다 이러한 오류 :

+0

고마워, 그건 하나의 오류를 제거하지만 다른 하나는 남아있다. '.' 14 행에서 분명히 불법입니다. http://pastebin.com/0UMTPdrp - 잡히지 않습니다. SyntaxError : 예기치 않은 토큰입니다. - 이것은 페이스 북에서 직접 찍은대로 혼란. 자신의 코드가 잘못되었습니다! – Francesca

+1

@Francesca 코드가 정확합니다. philippeharewood.com/facebook/hello.html에서 수정 된 버전을 볼 수 있습니다. – phwd

0

을 피하기 위해 코드를 직접 붙여 넣으면 어떤 식 으로든 이상한 문자가 그 안에 들어갑니다. 필자는 직접 복사 및 붙여 넣기와 달리 물리적으로 다시 작성하여 해결했습니다.

관련 문제