Is there an FB.Event.monitor('auth.statusChange', function(session) ) equivalent?
rbahumi opened this issue · 4 comments
Hi,
I ran a small experiment with the plugin, trying to call dialog('feed')
after a call to logout
.
The results were that the plugin has stopped functioning afterwards. I tried calling login
again, but
that didn't do anything.
I guess that according the normal flow of things, this shouldn't happen. But what if the token has been expired, or if the user had deauthorise my app?
- Should I call
login
before any call to thedialog
? - Is there an
FB.Event.monitor('auth.statusChange', function(session) )
equivalent that notifies when the user's
status changes?
Regards, Roei.
Below are some extra details.
This is my index.html:
<head>
<script type="text/javascript" src="js/cordova-2.0.0.js"></script>
<script type="text/javascript" src="js/plugins/FacebookConnect.js"></script>
<script type="text/javascript" src="js/jquery.min.1.7.1.js"></script>
<script>
var APP_ID = '352872202215';
document.addEventListener('deviceready', bar, false);
function bar(){
//alert('deviceready');
facebookConnect = window.plugins.facebookConnect;
}
function login(){
alert('login');
facebookConnect.login({permissions: ["email", "user_about_me"], appId: APP_ID},
function(result) {
console.log("FacebookConnect.login:" + JSON.stringify(result));
// Check for cancellation/error
if(result.cancelled || result.error) {
console.log("FacebookConnect.login:failedWithError:" + result.message);
return;
}
else console.log('succeeded!');
});
}
function logout(){
alert('logout!');
facebookConnect.logout(function(response){
console.log("FacebookConnect.logout:" + JSON.stringify(response));
});
}
function post(){
alert('post!');
// Feed dialog example
var dialogOptions = {
method: 'feed',
//app_id: APP_ID,
name: 'roei',
link: 'https://surf-space.com/spots/israel',
description: 'stuff...',
picture: 'http://fbrell.com/f8.jpg'
}
facebookConnect.dialog('feed', dialogOptions, function(response) {
console.log("FacebookConnect.dialog:" + JSON.stringify(response));
});
};
</script>
</head>
<body>
<button type="button" id="login" data-inline="false" onclick="login();">login</button>
<button type="button" id="post" data-inline="false" onclick="post();">post</button>
<button type="button" id="logout" data-inline="false" onclick="logout();">logout</button>
</body>
</html>
This is the console.log output after calling logout
:
2012-08-20 23:00:47.076 surf_space[3893:c07] -[FacebookConnect facebook]
[Line 32] ERROR: You must provide a non-empty appId.
2012-08-20 23:00:47.079 surf_space[3893:c07] PluginResult:toJSONString -
{"status":1,"message":"OK","keepCallback":false}
2012-08-20 23:00:47.080 surf_space[3893:c07] PluginResult
toSuccessCallbackString: cordova.callbackSuccess('FacebookConnect2',
{"status":1,"message":"OK","keepCallback":false});
2012-08-20 23:00:47.081 surf_space[3893:c07] [INFO] FacebookConnect.logout:"OK"
Please note that if I run login
again, everything works as expected.
But, when calling the dialog('feed')
right away after logout, this is the console.log output:
2012-08-20 23:10:49.982 surf_space[3893:c07] -[FacebookConnect facebook]
[Line 32] ERROR: You must provide a non-empty appId.
2012-08-20 23:10:49.983 surf_space[3893:c07] *** WebKit discarded an uncaught
exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener:
delegate: <NSInvalidArgumentException> *** -[CDVJKDictionary setObject:forKey:]:
attempt to insert nil value (key: app_id)
And the plugin doesn't recover from that....
Another thing, I am running these tests on an iPhone 5.1 simulator without a facebook app installed.
All authentications are going directly to the Safari browser.
- You should clearly login before doing any other call. The app should not however (but it may crash in the facebook sdk part). I'll patch that.
- There is no statusChange event yet, but if it is provided by the facebook native sdk, it should be quite straightforward to implement (PR welcomed ;-)!)
Perhaps, you should call initWithAppId
js method to verify a session active when the app starts or resumes