LoginSignup
7
7

More than 5 years have passed since last update.

Titanium:Facebookとの連携

Last updated at Posted at 2013-06-05
  • 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);
        }
    }
);
7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7