-
-
Save savage69kr/3082933 to your computer and use it in GitHub Desktop.
Facebook API が callback 地獄になる対策的な。こういうイメージかなあ?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
</head> | |
<body> | |
<div id="fb-root"></div> | |
<script src="//connect.facebook.net/en_US/all.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> | |
<script src="facebook-deferred.js"></script> | |
<script> | |
FB.init({appId: '114052475334124', status: true, cookie: true, xfbml: true}); | |
FB.defer.api('/1276368138').done(function(response){ | |
$('<p>').text('Author is ' + response.name).appendTo($('#profile')); | |
}); | |
</script> | |
<div class="container"> | |
<div class="page-header"> | |
<h1>facebook-deferred.js example</h1> | |
</div> | |
<div id="profile"></div> | |
</div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* facebook-deferred.js | |
* | |
* @author Keisuke SATO <[email protected]> | |
*/ | |
FB.defer = {}; | |
// api method. | |
FB.defer.api = function() { | |
var dfd = new jQuery.Deferred(); | |
FB.api.apply(this, $.merge(arguments, [function(response) { | |
// TODO: error handling. | |
dfd.resolve(response); | |
}])); | |
return dfd.promise(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment