- tiapp.xmlのModuleにfacebookを追加
ログイン-ログアウト ボタン
var win = Ti.UI.createWindow({backgroundColor: 'white'});
var fb = require('facebook');
fb.appid = FACEBOOK_APP_ID;
fb.permissions = ['publish_stream'];
fb.forceDialogAuth = true;
fb.addEventListener('login', function(e) {
if (e.success) {
alert('Logged in');
}
});
fb.addEventListener('logout', function(e) {
alert('Logged out');
});
// Add the button. Note that it doesn't need a click event listener.
win.add(fb.createLoginButton({
top : 50,
style : fb.BUTTON_STYLE_WIDE
}));
win.open()
情報の取得
自分のユーザネームを取得
fb.requestWithGraphPath(
'me',
{},
"GET",
function(e) {
if (e.success) {
var obj = JSON.parse(e.result);
alert("Success: " + obj.name);
}
}
);
ウォールへの投稿
fb.requestWithGraphPath(
'me/feed',
{
message: "GraphAPIのテスト"
},
"POST",
function(e) {
if (e.success) {
alert("Success" + e.result);
}
}
);