3
votes

Its been a couple of days i started working with titanium and got familiar with the framework. Its really cool framework. Now i am building an app trying to connect with facebook.... I also registered an app on facebook developers and got the id.But it couldnt connect for some reason... I am getting errors like:

Message: Uncaught TypeError: Cannot set property 'appid' of undefined

My code is as follows:(http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.Facebook-property-loggedIn)

// Don't forget to set your appid and requested permissions, else the login button
// won't be effective.
Titanium.Facebook.appid = "xxxxxxxxxxxxxxx";
Titanium.Facebook.permissions = ['publish_stream', 'read_stream'];
Titanium.Facebook.addEventListener('login', function(e) {
    if (e.success) {
        alert('Logged in');
    }
});
Titanium.Facebook.addEventListener('logout', function(e) {
    alert('Logged out');
});

// add the button.  Note that it doesn't need a click event or anything.
Titanium.UI.currentWindow.add(Titanium.Facebook.createLoginButton({ top: 50, style: 'wide' }));

and in my tiapp.xml i added below code :

<property name="ti.facebook.appid">XXXXXXXXXXX</property>
<modules>
        <module platform="android">facebook</module>
 </modules>

one last thing i am using android 2.2 similator... I know i should ask this question in titanium appcelerator forums ... i didn't it, but did get any response ... Thought some geeks here might help me.. Thanks

1
have a look at titanium cookbook - DomincJune
i followed the book so closely but couldnt get through with this.. - troy

1 Answers

4
votes

I am using titanium studio with 3.1 SDK. So i guess Titanium.Facebook has been deprecated in newer versions.http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.Facebook.LoginButton)

Below code snippet works for me..

var win = Ti.UI.createWindow({backgroundColor: 'white'});
var fb = require('facebook');
fb.appid = "xxxxxxxxxxxxxxx";
fb.permissions =  ['publish_stream'];

fb.addEventListener('login', function(e) {
    if (e.success) {
        alert('Logged in');
    }
});
fb.addEventListener('logout', function(e) {
    alert('Logged out');
});
win.add(fb.createLoginButton({
    top : 50,
    style : fb.BUTTON_STYLE_WIDE
}));
win.open()

Cheers...