2

JavaScript SDK를 사용하는 방법을 알아 내려고합니다. JavaScrip을 처음 사용합니다. PHP SDK를 사용할 수 있었지만 내 물건 클라이언트를 실행하고 싶습니다. Anyhoo, 개발 사이트에서 SDK 설명서를 실제로 이해하지 못합니다. 그래서 기본 코드입니다 : 내가 이해 생각JavaScript SDK Facebook : 초기화 스크립트의 문제

<div id="fb-root"></div> 
<script> 
window.fbAsyncInit = function() { 
    FB.init({ 
      appId  : 'YOUR_APP_ID', // App ID 
      channelUrl : '//WWW.YOUR_DOMAIN.COM/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 initialization code here 
}; 

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

... 그것은 SDK를로드 한 후이로드되면 FB.init 물건을 실행합니다. 나는 OAuth의 모든 것을 넣을 곳을 모른다. 그리고 로그인 요청을 구조화하는 방법 (예를 들어, 로그인 버튼에 로그인하지 않고 액세스 토큰 등을 반환한다면).

누군가 내 .이 시작되는 부분을 통해 손 나는 모든 곳에서 검색 한 난 그냥 아주 이해가 안가

편집 :.

좋아, 두 번째 인증을 시도 작동하지 않았다 :.

<div id="fb-root"></div> 
<script> 
window.fbAsyncInit = function() { 
    FB.init({ 
      appId  : 'XXX', // App ID 
      channelUrl : 'XXX', // Channel File 
      status  : true, // check login status 
      cookie  : true, // enable cookies to allow the server to access the session 
      xfbml  : true // parse XFBML 
    }); 

    // Additional initialization code here 
    FB.getLoginStatus(function(response) { 
      if (response.status === 'connected') { 
       // the user is logged in and connected to your 
       // app, and response.authResponse supplies 
       // the user's ID, a valid access token, a signed 
       // request, and the time the access token 
       // and signed request each expire 
       var uid = response.authResponse.userID; 

       var accessToken = response.authResponse.accessToken; 
       FB.api('/me', function(response) { 
         alert(response.name); 
       }); 

      } else if (response.status === 'not_authorized') { 
       FB.login(function(response) { 
         if (response.authResponse) { 
          console.log('Welcome! Fetching your information.... '); 
          FB.api('/me', function(response) { 
            console.log('Good to see you, ' + response.name + '.'); 
            FB.logout(function(response) { 
              console.log('Logged out.'); 
            }); 
          }); 
         } else { 
          console.log('User cancelled login or did not fully authorize.'); 
         } 
}, {scope: 'email'}); 
      } else { 

      } 
    }) 

}; 

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

</script> 

감사합니다.

답변

1

이 줄 바로 아래에, // Additional initialization code here 은 oauth 항목이있는 곳입니다.

먼저 FB.getLoginStatus()에 전화하는 데 익숙해지는 것이 좋습니다. 참조 : http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/


EDIT 당신이 getLoginStatus 확인했습니다

FB.api('/me', function(response) { 
     alert(response.name); 
}); 

및 후에 만이이 window.fbAsyncInit의 함수 내에서 수행해야 위의 질문 편집에 따라

() 사용자가 로그인했는지 여부를 알 수 있습니다.

+0

편집을 참조하십시오. 귀하의 도움에 감사드립니다 btw :) – JoshDG

+0

편집 agin. 아직 아무것도 나타나지 않습니다. 콘솔에 아무것도 없습니다. – JoshDG

+1

잠시만 기다려주세요. 구문 오류가 표시됩니다. – JoshDG