Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there an FB.Event.monitor('auth.statusChange', function(session) ) equivalent? #11

Open
rbahumi opened this issue Aug 20, 2012 · 4 comments

Comments

@rbahumi
Copy link

rbahumi commented Aug 20, 2012

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?

  1. Should I call login before any call to the dialog?
  2. Is there an FB.Event.monitor('auth.statusChange', function(session) ) equivalent that notifies when the user's
    status changes?

Regards, Roei.

@rbahumi
Copy link
Author

rbahumi commented Aug 20, 2012

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....

@rbahumi
Copy link
Author

rbahumi commented Aug 21, 2012

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.

@mgcrea
Copy link
Owner

mgcrea commented Aug 23, 2012

  1. 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.
  2. 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 ;-)!)

@dvdvck
Copy link

dvdvck commented Dec 11, 2012

Perhaps, you should call initWithAppId js method to verify a session active when the app starts or resumes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants