0
일단 사용자가 내 앱을 승인하면 서명 된 요청을 구문 분석해야 사용자 ID 등을 액세스 할 수 있습니다. 내 코드에서 URL을 처리하는 페이지에 URL을 넣을 수 있습니까? 코드 예제가 필요합니다. 설명서를 살펴본 결과 캔버스 응용 프로그램에서이 작업을 수행하는 방법이 명확하게 설명되어 있지 않습니다. redirectUrl 변수에는 캔버스 앱 자체의 URL이 있습니다. 대신 서명 된 요청을 구문 분석하는 코드의 URL을 포함해야합니까? 나는 잘 모르겠다.Facebook 캔버스 앱 승인에서 서명 된 요청을받는 방법은 무엇입니까?
<body>
<div id="fb-root"></div>
<script type="text/javascript">
$(document).ready(function(){
var appId = 278*****2040;
// If logging in as a Facebook canvas application use this URL.
var redirectUrl = "http://apps.facebook.com/MYAPP";
// If the user did not grant the app authorization go ahead and
// tell them that. Stop code execution.
if (0 <= window.location.href.indexOf ("error_reason"))
{
$('#authCancel').empty();
$(document.body).append ("<p>Authorization denied!</p>");
return;
}
// When the Facebook SDK script has finished loading init the
// SDK and then get the login status of the user. The status is
// reported in the handler.
window.fbAsyncInit = function(){
//debugger;
FB.init({
appId : 278****40,
status : true,
cookie : true,
oauth : true
});
// Sandbox Mode must be disabled in the application's settings
// otherwise the callback will never be invoked. Monitoring network
// traffic will show an error message in the response. Change the
// Sandbox Mode setting in: App Settings - Advanced - Authentication.
FB.getLoginStatus (onCheckLoginStatus);
};
// Loads the Facebook SDK script.
(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));
// Handles the response from getting the user's login status.
// If the user is logged in and the app is authorized go ahead
// and start running the application. If they are not logged in
// then redirect to the auth dialog.
function onCheckLoginStatus (response)
{
if (response.status != "connected")
{
top.location.href = "https://www.facebook.com/dialog/oauth?client_id=" + appId + "&redirect_uri=" + encodeURIComponent (redirectUrl) + "&scope=user_photos,friends_photos";
}
else
{
// Start the application (this is just demo code)!
$(document.body).append ("<p>Authorized!</p>");
FB.api('/me', function (response) {
$(document.body).append ("<pre>" + JSON.stringify (response, null, "\t") + "</pre>");
});
}
}
});
</script>