Facebook

Is there a way to use Facebook on Windows?

We use it for user authentication for the leaderboards and for social sharing.

Another question, how can we know what plugin is supported on what platform?

You should edit the plugin directory and for every plugin list all platforms it is supported.

Facebook does not offer an SDK for OS X or Win32.  You’ll have to use their graph http API via network requests instead.

Also, if you look at the top of each plugin documentation page (see link below), they indicate which platforms they support.

   https://docs.coronalabs.com/daily/plugin/index.html

For example, if you look at the facebook plugin page (link below), notice that it shows a “Platforms” row at the top of the page and only Android and iOS are supported.

   https://docs.coronalabs.com/daily/plugin/facebook/index.html

Thank you Joshua.

Should I start from scratch or has any fellow Corona developer played with the facebook API?

I’m not aware of any, but that doesn’t mean it hasn’t been done.  Maybe you should leave this thread open so if someone did implement a Lua based facebook library, they can offer it here. 

Facebook does not offer an SDK for OS X or Win32.  You’ll have to use their graph http API via network requests instead.

Also, if you look at the top of each plugin documentation page (see link below), they indicate which platforms they support.

   https://docs.coronalabs.com/daily/plugin/index.html

For example, if you look at the facebook plugin page (link below), notice that it shows a “Platforms” row at the top of the page and only Android and iOS are supported.

   https://docs.coronalabs.com/daily/plugin/facebook/index.html

Thank you Joshua.

Should I start from scratch or has any fellow Corona developer played with the facebook API?

I’m not aware of any, but that doesn’t mean it hasn’t been done.  Maybe you should leave this thread open so if someone did implement a Lua based facebook library, they can offer it here. 

We are porting one of our games to Windows and OS X.

Would be great if we could implement facebook login.

Here is what I found on the facebook docs:

To use Facebook Login in a desktop app, you’ll need to be able to embed a web browser (sometimes called a webview) within the app to perform the login process

And here is what should be done (from their docs):

Invoking the login dialog

Your app must initiate a redirect to an endpoint which will display the login dialog:

https://www.facebook.com/dialog/oauth?
client_id={app-id}
&redirect_uri={redirect-uri}

This endpoint has the following required parameters:

  • client_id. The ID of your app, found in your app’s dashboard.
  • redirect_uri. The URL that you want to redirect the person logging in back to. This URL will capture the response from the Login Dialog. If you are using this in a webview within a desktop app, this must be set to https://www.facebook.com/connect/login_success.html.

Does that mean we have to open a web-view and then redirect to the above url?

How will we get the response?

Does Windows and/or OS X support webviews?

Any help on this would be greatly appreciated.

As of right now, webViews are not supported in desktop builds.

hm… I might be wrong but it seems to work on OS X.

Compiled on of our games for OS X and the Help window was shown and scrollable (it shows local HTML file in a webview)…

Rob means that WebViews are not supported by Win32 desktop apps.  (This is the Win32 app forum.)

WebViews are supported by OS X desktop apps.

local json = require("json") local myfbid W,H = display.contentWidth,display.contentHeight local userdatas local fbcode local function getFBData(token) local function networkListener( event ) if ( event.isError ) then print( "Network error!" ) else print(event.response) local decoded, pos, msg = json.decode( event.response ) if not decoded then print( "Decode failed at "..tostring(pos)..": "..tostring(msg) ) else userdatas = decoded end end end network.request( "https://graph.facebook.com/v2.3/me?fields=id,email,name,picture&access\_token="..token, "GET", networkListener ) end local function loopCheckIsLogin() local function networkListener( event ) if ( event.isError ) then else if event.status==200 then print("not yet") local decoded, pos, msg = json.decode( event.response ) if not decoded then print( "Decode failed at "..tostring(pos)..": "..tostring(msg) ) else fbcode:removeSelf( ) getFBData(decoded.access\_token) end else print("not yet") timer.performWithDelay( 5000, loopCheckIsLogin) end end end local headers = {} headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Accept-Language"] = "en-US" local body = "type=device\_token&client\_id=1053169668066995&code=".. \_G.fbcode local params = {} params.headers = headers params.body = body network.request( "https://graph.facebook.com/oauth/device", "POST", networkListener, params ) end local function askLogin() local function networkListener( event ) if ( event.isError ) then else local decoded, pos, msg = json.decode( event.response ) if not decoded then print( "Decode failed at "..tostring(pos)..": "..tostring(msg) ) else fbcode = native.newTextField( W/2, H/4, 120, 30 ) fbcode.text = decoded.user\_code system.openURL("https://facebook.com/device") \_G.fbcode = decoded.code timer.performWithDelay( 5000, loopCheckIsLogin) end end end local headers = {} headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Accept-Language"] = "en-US" local body = "type=device\_code&client\_id=1053169668066995&scope=public\_profile" local params = {} params.headers = headers params.body = body network.request( "https://graph.facebook.com/oauth/device", "POST", networkListener, params ) end askLogin()

Please read this https://developers.facebook.com/docs/facebook-login/for-devices

We are porting one of our games to Windows and OS X.

Would be great if we could implement facebook login.

Here is what I found on the facebook docs:

To use Facebook Login in a desktop app, you’ll need to be able to embed a web browser (sometimes called a webview) within the app to perform the login process

And here is what should be done (from their docs):

Invoking the login dialog

Your app must initiate a redirect to an endpoint which will display the login dialog:

https://www.facebook.com/dialog/oauth?
client_id={app-id}
&redirect_uri={redirect-uri}

This endpoint has the following required parameters:

  • client_id. The ID of your app, found in your app’s dashboard.
  • redirect_uri. The URL that you want to redirect the person logging in back to. This URL will capture the response from the Login Dialog. If you are using this in a webview within a desktop app, this must be set to https://www.facebook.com/connect/login_success.html.

Does that mean we have to open a web-view and then redirect to the above url?

How will we get the response?

Does Windows and/or OS X support webviews?

Any help on this would be greatly appreciated.

As of right now, webViews are not supported in desktop builds.

hm… I might be wrong but it seems to work on OS X.

Compiled on of our games for OS X and the Help window was shown and scrollable (it shows local HTML file in a webview)…

Rob means that WebViews are not supported by Win32 desktop apps.  (This is the Win32 app forum.)

WebViews are supported by OS X desktop apps.

local json = require("json") local myfbid W,H = display.contentWidth,display.contentHeight local userdatas local fbcode local function getFBData(token) local function networkListener( event ) if ( event.isError ) then print( "Network error!" ) else print(event.response) local decoded, pos, msg = json.decode( event.response ) if not decoded then print( "Decode failed at "..tostring(pos)..": "..tostring(msg) ) else userdatas = decoded end end end network.request( "https://graph.facebook.com/v2.3/me?fields=id,email,name,picture&access\_token="..token, "GET", networkListener ) end local function loopCheckIsLogin() local function networkListener( event ) if ( event.isError ) then else if event.status==200 then print("not yet") local decoded, pos, msg = json.decode( event.response ) if not decoded then print( "Decode failed at "..tostring(pos)..": "..tostring(msg) ) else fbcode:removeSelf( ) getFBData(decoded.access\_token) end else print("not yet") timer.performWithDelay( 5000, loopCheckIsLogin) end end end local headers = {} headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Accept-Language"] = "en-US" local body = "type=device\_token&client\_id=1053169668066995&code=".. \_G.fbcode local params = {} params.headers = headers params.body = body network.request( "https://graph.facebook.com/oauth/device", "POST", networkListener, params ) end local function askLogin() local function networkListener( event ) if ( event.isError ) then else local decoded, pos, msg = json.decode( event.response ) if not decoded then print( "Decode failed at "..tostring(pos)..": "..tostring(msg) ) else fbcode = native.newTextField( W/2, H/4, 120, 30 ) fbcode.text = decoded.user\_code system.openURL("https://facebook.com/device") \_G.fbcode = decoded.code timer.performWithDelay( 5000, loopCheckIsLogin) end end end local headers = {} headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Accept-Language"] = "en-US" local body = "type=device\_code&client\_id=1053169668066995&scope=public\_profile" local params = {} params.headers = headers params.body = body network.request( "https://graph.facebook.com/oauth/device", "POST", networkListener, params ) end askLogin()

Please read this https://developers.facebook.com/docs/facebook-login/for-devices