HELP with Facebook plugin v4 formatting for "facebook.request"

I have tried:

facebook.login(V.facebookID,FB.listener, {“user_friends”, “email”, “public_profile”})

and it appears to grant my App permission. But it passes no data back to me through the listener other than my user access token through event.token.

However, I have also tried:

facebook.request(“me”,“GET”,{“user_friends”, “email”, “public_profile”})

and received an error that ‘fields’ must be explicit

So then I tried:

facebook.request(“me”,“GET”,{fields=“user_friends”, “email”, “public_profile”}})

I received an error without any message. Nowhere in all the Forums and Corona API can I find a single example of how to accomplish this simple request after the login is successful. Please help me understand how the pluginv4 formats this data for Facebook and update the FB documentation in the Corona API accordingly.

Also, there are numerous conflicts regarding issues in the documentation because Corona is currently supporting both the original version (require “facebook”) and the new plugin v4 (require “plugin.facebook.v4”) modules. Although there are migration notes, etc… it is far from clear how to get any farther than a login.

Any help here would be very much appreciated.

Hi,

I certainly won’t disagree with you about confusion in the docs. Looking at FB docs directly, did you try this method yet?

facebook.request(“me”,“GET”,{fields=“user_friends,email,public_profile”})

I didn’t work on the plugin or docs, but just trying to see if there is anything obvious.

Cheers.

Also it appears that you’re confusing permissions with data fields in the “me” object. Things like “user_friends” and “public_profile” are permissions. They have to be requested as part of the login process. You shouldn’t request them until you need them by re-calling login at the appropriate time.

The “me” object is a special “user” object that references you. Check out the reference on the “user” object:

https://developers.facebook.com/docs/graph-api/reference/user/

You can see you can get things like the id, first_name, favorite_teams and host of profile goodies about a user if they have shared it with you and they filled it out. Of course you should have full access to your own user account.

Things like “email”, and this is where confusion comes from are both a permission and a data element of the user object. When specified with a facebook.login() call, it’s asking permission to access the user’s “email” field. The user running the app would have to grant permission. Without it you cannot get access to the “email” field that’s part of the user object.

Chris pointed out the proper use of the fields syntax, but it needs to be fields that are part of the user object:

facebook.request(“me”,“GET”,{fields=“id, first_name, last_name, email, gender, hometown”})

etc.

The .login call should trigger your listener with an event.type of session. After  you confirm that you successfully requested the additional permissions then you can do the .request() call. It will trigger the listener a second time with an event.type of “request”. At this point you can look at the data in event.response which will be a table of returned data.

Rob

Hi Rob,

Just as Facebook includes sample apps and code, has Corona created a FB sample app for the v4 plugin? I have found nothing useful.

May I recommend you watch this Facebook developer video and see how their sample apps use use FB API (aka Facebook Graph API)?

You have probably already seen this video. For those following this post, it is very beneficial. About half way down the page: https://developers.facebook.com/docs/facebook-login/overview

If we had one or more of these sample apps within Corona, we would be better empowered to learn and implement the FB Graph API. As it is now, we are forced to both learn the FB Graph API and guess/hack our way to learn how to use it from within Corona, through laborious trial and error.

I noticed from an online note on the Corona website that plugin v4 does not support facebook.dialog. Is there any plan to do so in the future? Until then, we are forced to create our own framework to display Facebook users, names and images, and scroll through them in order to select them - a  time-consuming framework task for anyone.

Your help is very much appreciated as always.

Very kindly yours,

-Troy

The current Facebook sample app included with the latest daily builds is V4 compatible.

Rob

Hi Rob,

I have now integrated the code from the Facebook Sample App that is included in the build I’m using (build 2802).

  1. The code appears to be working, but I’ve noticed that the sample app requires the Facebook user to authorize posting via “publish_actions”. Because I’d like to offer Facebook at the start of my App, I don’t want to require the gamer to provide such authorizations until after they have been playing. So, I replaced {“publish_actions”} with {“public_profile”,“user_friends”,“email” and “publish_actions” to see if it worked. When the listener comes back, it prints the table and shows that all these permissions have been properly granted. So, if I were to eliminate the “publish_actions” from the initial list, and later seek to perform another login with the entire list for posting, is there any problem I will encounter in doing so?

  2. when integrating the code into my app, I discovered that my app is suspended (while my iphone opens Facebook) during login. This is obviously required and would be fine, but it abandons the subroutine running when it does this. And when it does return, it does NOT continue the subroutine where it left. This would be fine, but even the code in your sample app never has a chance to continue once the login interrupts the app. I resolved the issue by placing all listener events into a que (as well as the contents of fbCommand) which are then executed in my sequential gameloop so that I always know when the events are processed. Is it a normal Corona consequence that code is not resumed where it was when an application resumes (when it returns from Facebook)?

The biggest issue this presents is such that the only way I can tell if the app is returning from Facebook, would I am concerned about doing, would be to set a flag, and then execute specific code when Corona resumes. But then, it will not be so simple to figure out what code previously executed prior to the suspension and which code still needs to be run.

For these reasons, it appears as if the Facebook sample app would not actually work properly - which I cannot imagine. Can you please confirm that Corona has a FacebookAppID for the sample app and that it runs for you without the issues presented here? If so, I will then create a subset of my app with nothing more than the Facebook issues presented here in order to resolve them.

Thank you kindly,

-Troy

For #1, Facebook wants you delay more aggressive permissions until you need them. You are doing this correctly. Let me see if I can get an answer for #2.

Rob

For question #2. Yes, Facebook will suspend your app to handle logins. Corona SDK is an event driven system. The concept of a gameLoop is really foreign to how Corona does things. If you’re implementing a gameLoop it should only be responsible for your game bits. Many things in Corona SDK are asynchronous and your gameLoop can’t pause and wait on them to complete.

If you get to a point in your gameLoop where you need to know if you can make a facebook request or not, you can check facebook.getCurrentAccessToken() to check to see if you have the permissions to avoid excessive logins.

And to your point about facebook.dialog… is this different than the facebook.showDialog() API? What is it you’re looking for this to do?

Rob

Hi Rob,

You wrote, “The concept of a gameLoop is really foreign to how Corona does things.” Well then, how does Corona recommend game developers manage complex games when code that is timer-based happens to check variables that are in the process of changing in other timer based code? (i.e. timerperformwithdelay, transition.to, etc…) Can you recommend a better way that is not foreign to Corona than the solution I have found? Currently, I “que” events which could create a conflict and then process them sequentially in a ‘single’ timer-based ‘gameloop’. I’m always interested to learn of better ways to code.

Based upon your comments, I now understand that facebook.login (listener, permissionsToRequest) is the purpose of facebook.login. And the Sample App’s code (the one shipping with the latest daily build) does the job of checking if facebook is active and if we already have an access_token - a step that is necessary before we can ask for permissions. The Sample App sets permissionsToRequest = “publish_actions”, but I’ve since found “public_profile”, “user_friends” and “email” as options that can be requested independently or altogether as a list, (i.e. facebook.login( listener, {"publish_actions, “public_profile”, “user_friends”,“email”} )

However, what is not so clear is the fact that any “request” for information from Facebook does NOT use a list, but instead, a comma-delimited field (i.e. facebook.request(“me”,“GET”,{fields=“id, first_name, last_name, email”}). Can you direct me to where I can find a complete list of items to include in the “fields” comma-delimited list? Perhaps this is beyond your scope of support, since it is Facebook specific, but any help would be appreciated - I know I speak for the community when I tell you that your contribution to our work here online has been invaluable.

Regarding showDialog, I’ll have to come back to this after I’ve used it. In the v4 plugin notes, there are comments that v4 does not fully support it. I’m curious to know if when I want to have my game send a virtual item to a Facebook friend, can I ask for a dialog in which the gamer can choose one or more friends to send or post to?

Very kindly as always,

-Troy

Any answers to these questions from above?

However, what is not so clear is the fact that any “request” for information from Facebook does NOT use a list, but instead, a comma-delimited field (i.e. facebook.request(“me”,“GET”,{fields=“id, first_name, last_name, email”}). Can you direct me to where I can find a complete list of items to include in the “fields” comma-delimited list, other than the FB Graph API?

Regarding showDialog, I’ll have to come back to this after I’ve used it. In the v4 plugin notes, there are comments that v4 does not fully support it. But after another look, v4 has some support for it. I’m curious to know…if when I want to have my game send a virtual item to a Facebook friend, can I ask for a dialog in which the gamer can choose one or more friends to send or post to?

For the fields you can use in the “me” GET request, I can only point you to the Graph API docs. It is the source. If we produced a list, perhaps in a easier to understand format, then we would be on the hook for keeping that list updated whenever Facebook adds, removes or changes things. They do that too often. The “me” object is a “user” object when looking through the Graph API doc.

That note in the v4 is referring to some dialogs that we want to eventually support. Any dialog supported by the previous plugin should be supported.

Rob