Facebook login listener

The facebook instructions state that a facebook login should only be performed once (or when permissions are revoked) and then only occasionally to increase app permissions.

The docs (http://docs.coronalabs.com/plugin/facebook/login.html) state that only the facebook API’s login function take a listener function (which receives Facebook Graph API responses.)

If facebook login is only meant to be called once how can other requests be made?

I am seeing a user request to login to facebook every time facebook.login() is called, which means I either can’t make requests for friend lists or I annoy the user regularly.

How can we listen for facebook API responses without forcing the user to login every time?

Hi Matt,

Rob is more versed on Facebook than I am, so I may end up directing this to him, but in the meantime, can you give me a more detailed example of what you want to “listen” for and when?

In any case, I’m pretty sure that (like many ad plugins, in a way), the listener function that you define in “.login()” will also be called when you do things like “.request()”, not just on “.login()”, meaning that you define the listener in the login, but then it’s used in other Facebook calls too. So, you can check the “fbconnect” event for various parameters and results.

http://docs.coronalabs.com/api/event/fbconnect/index.html

Take care,

Brent

Hi,

Let’s say I want to request a list of the user’s friends from facebook. Once the app is started up, to be able to receive the list of friends from Graph API the listener must be registered with the facebook API. The only way to register the listener is to call facebook.login() This means that the FB API attempts to perform a login, which ends up switching to the FB or Safari browser for approval.

Either I’m missing something or there’s a flaw in the API. Is it possible to retrieve data from the Graph API without calling login?

Thanks,

Matt

Hi Matt,

What happens if you call facebook.request()? Do you get any response sent to the listener that you defined in the .login() API?

[lua]

facebook.request( “me/friends” )

[/lua]

And, of course, if the app starts up and the user is not logged into FB, then naturally you’ll need to log them in. You can’t get somebody’s friends without knowing who they are. :slight_smile:

Brent

For facebook, you call facebook.login() to setup your listener and ask the user for basic permissions.  If you need extra permissions like posting, extra profile things like email addresses and such, you have to call facebook.login() again this time with the extended permissions.  After that you can make the calls.

me/friends only returns friends who have your app installed,

many actions require you to submit your app to Facebook to get your features approved before anyone other than registered test accounts can use them.

Rob

Let’s say my app has already asked for the necessary permissions the first time it is loaded. Then, the next time the user/player runs it, the user wants a list of friends who have the app installed. This time, we don’t need to ask for any more permissions so we don’t call login() - we just call request(). The problem here is that, without having called login() first, there is no registered listener function for the list of friends to be returned by.

Why would you not have a listener?  If you cold start your app, you have to call facebook.login() at the beginning of your program to setup the listener and refetch your token and such.  You shouldn’t get prompted for permissions unless you’ve done a .logout() along the way.

Rob

The problem is, for me at least, every time I call facebook.login() it redirects to the FB app or Safari page to auth the app. This is with an app approved in FB for live.

You should only get to Safari if you don’t have the Facebook app installed.  If you do, it should do a fast-app-switch to the facebook app and switch back.  This is how Facebook does things.  If you have the facebook app installed and you’re getting to a safari style dialog box, then perhaps your build.settings isn’t handling the URL scheme correctly.

Rob

But should it ask for permissions every time the app switches, or should it switch and switch back again quickly with no user interaction?

It should fast switch and not ask for permissions.

Rob

Hi Matt,

Rob is more versed on Facebook than I am, so I may end up directing this to him, but in the meantime, can you give me a more detailed example of what you want to “listen” for and when?

In any case, I’m pretty sure that (like many ad plugins, in a way), the listener function that you define in “.login()” will also be called when you do things like “.request()”, not just on “.login()”, meaning that you define the listener in the login, but then it’s used in other Facebook calls too. So, you can check the “fbconnect” event for various parameters and results.

http://docs.coronalabs.com/api/event/fbconnect/index.html

Take care,

Brent

Hi,

Let’s say I want to request a list of the user’s friends from facebook. Once the app is started up, to be able to receive the list of friends from Graph API the listener must be registered with the facebook API. The only way to register the listener is to call facebook.login() This means that the FB API attempts to perform a login, which ends up switching to the FB or Safari browser for approval.

Either I’m missing something or there’s a flaw in the API. Is it possible to retrieve data from the Graph API without calling login?

Thanks,

Matt

Hi Matt,

What happens if you call facebook.request()? Do you get any response sent to the listener that you defined in the .login() API?

[lua]

facebook.request( “me/friends” )

[/lua]

And, of course, if the app starts up and the user is not logged into FB, then naturally you’ll need to log them in. You can’t get somebody’s friends without knowing who they are. :slight_smile:

Brent

For facebook, you call facebook.login() to setup your listener and ask the user for basic permissions.  If you need extra permissions like posting, extra profile things like email addresses and such, you have to call facebook.login() again this time with the extended permissions.  After that you can make the calls.

me/friends only returns friends who have your app installed,

many actions require you to submit your app to Facebook to get your features approved before anyone other than registered test accounts can use them.

Rob

Let’s say my app has already asked for the necessary permissions the first time it is loaded. Then, the next time the user/player runs it, the user wants a list of friends who have the app installed. This time, we don’t need to ask for any more permissions so we don’t call login() - we just call request(). The problem here is that, without having called login() first, there is no registered listener function for the list of friends to be returned by.

Why would you not have a listener?  If you cold start your app, you have to call facebook.login() at the beginning of your program to setup the listener and refetch your token and such.  You shouldn’t get prompted for permissions unless you’ve done a .logout() along the way.

Rob

The problem is, for me at least, every time I call facebook.login() it redirects to the FB app or Safari page to auth the app. This is with an app approved in FB for live.

You should only get to Safari if you don’t have the Facebook app installed.  If you do, it should do a fast-app-switch to the facebook app and switch back.  This is how Facebook does things.  If you have the facebook app installed and you’re getting to a safari style dialog box, then perhaps your build.settings isn’t handling the URL scheme correctly.

Rob

But should it ask for permissions every time the app switches, or should it switch and switch back again quickly with no user interaction?