To use Facebook Canvas Page, setup your new app from facebook developers App requires "App Display Name" and global unique "App Namespace". My example app uses:
- App Display Name: Helloworld
- App Namespace: bb-helloworld
After app created with captcha, Setting page of the app is opened. Its "App ID" and "App Secret" are given. My example app is:
- App ID: 228106443948163
Then pressing "App on Facebook", put "Secure Canvas URL" as "https://localhost:8000/" (https required). After pushing "Save Changes", new "Canvas age" is given under "Secure Canvas URL". (The URL starts with "http", but you should replace it with "https").
- Canvas "Page": https://apps.facebook.com/bb-helloworld/
- (raw Canvas URL): https://localhost:8000/
My example uses simple file based https server on node.js.
https server requires "key.pem" and "cert.pem" and "passphrase" of the key. These can be generated with "openssl" command as:
openssl req -new -keyout key.pem -text -out csr.pem
openssl req -x509 -in csr.pem -text -key key.pem -out cert.pem
(passphrase is set at the first command. it requires more than 4 charas.)
Launch https server as:
node simplehttpsserver.js
URL of the server is "https://localhost:8000/".
For loading JavaScript SDK, put a script in the html "body":
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function () {
FB.init({
appId: "228106443948163", // Your App ID
status: true,
cookie: true,
xfbml: true,
});
//alert("FB.init ok");
};
(function(d){
var id = 'facebook-jssdk';
if (d.getElementById(id)) {return;}
var 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>
for accessing faccebook personal data, use FB.api as:
FB.api("/me", function (res) {
alert(res.name);
});
or as:
FB.api("/me/feed", "post", {message: "from JS SDK"}, function (res) {
alert([res, res.error, res.id]);
});
See more info from documents: