Quick Links: Gideros Home | Download Gideros | Developer Guide
Facebook Android Plugin
  • ar2rsawseenar2rsawseen +1 -1 (+12 / -0 )
    Here is a Facebook Android Plugin.


    It will probably be included in next versions of Gideros, but for those of you who can't wait and want to try it out now (maybe even find any bugs :) ) here it is.

    I've attached two files, one (FacebookPlugin.zip) for Android exported project other (FacebookGideros.zip) a Gideros sample project.

    Installation instructions:
    • Download Facebook SDK here: http://developers.facebook.com/android/
    • Facebook SDK installation instructions here: http://developers.facebook.com/android/
      • Download and unzip
      • Import SDK into eclipse (Note you need to import it in workspace and check copy all files)

    • Export Gideros project to Android project
    • Import Android project to eclipse (Note you need to import it in workspace and check copy all files or Facebook SDK won't work)
    • Link Facebook SDK to your project:
      • Right click on your project
      • Select properties
      • Choose Android
      • In library section click Add and choose FacebookSDK
      • If it's not there or not linking properly, it means that you haven't imported FacebookSDK into eclipse or it's not in your workspace or your project is not in your workspace

    • Copy contents of FacebookPlugin.zip into your project:
      • Copy .so files to each separate armeabi folder
      • Copy facebook folder to src/giderosmobile/android/plugins folder

    • Inside your main activity:
      • Add lib as System.loadLibrary("facebook");
      • Add external class as "com.giderosmobile.android.plugins.facebook.GFacebook"
      • Add this line inside onActivityResult method: GFacebook.fb.authorizeCallback(requestCode, resultCode, data); (This step will not be needed, when plugin will be included in Gideros SDK)

    • Clean and launch the app, if it does not work, come and complain here, because I may have also screwed something up :)

    Attaching Facebook SDK I used while developing plugin
  • Very nice!
  • What exactly does it do with facebook?
    Like an app which posts to someone's page, or use their profile as a means of identification for a score table? Stuff like that?
  • ar2rsawseenar2rsawseen +1 -1
    Basically it can do all Graph API provides:

    Additionally it uses Facebook app for authentication or provides Web Dialogs.

    And there are also other web dialogs as one that allows user to post something to his wall, etc. :)
  • Dear @ar2rsawseen
    I think I have found one bug:

    local score = 10
    local paramaters = {
    score = score,
    fields = "firstname"
    facebook:graphRequest("me/scores", paramaters,"POST")

    This code closes player.
  • ar2rsawseenar2rsawseen +1 -1
    @achimeno thanks, I love when users provide test cases, I'll check it right now :)
  • Thank you @ar2rsawseen

    Another one:

    In the Java part you have a null in the String [] --> {"publish_actions", null}
  • ar2rsawseenar2rsawseen +1 -1
    @achimeno you are awesome! :)
    Fixed and pushed ;)
  • Any way to make it works in Gideros Player? I'm just curious how to make something harder than authorizing and sharing without it.
  • ar2rsawseenar2rsawseen +1 -1
    @unlying that's easy
    Export Gideros project as Android project, install plugin into exported project, delete assets folder, which is inside assets folder in exported project, and you have yourself Gideros player for Android with FB plugin.

    I assume there are same steps for IOS player :)
  • I'm using your sample app and i'm having these errors:
    "GFacebook cannot be resolved FacebookActivity.java"
    "Jar mismatch! Fix your dependencies"
    Something goes wrong for me.

    And any way to use it on PC?
  • ar2rsawseenar2rsawseen +1 -1
    @unlying unfortunately it can't be used on PC player. It's an Android plugin.
    So only if you can launch android apk on PC, like using BlueStacks or something, but that is usually not so handy.

    And about your problem, it looks like something similar to this:

    usually a problem in Android support library.

  • Emanuel +1 -1

    I did everything as described, but when I run the app it closes test alone ... what can be the problem?

    Result emulator logcat:

    05-03 19:07:57.186: W/dalvikvm(1837): JNI WARNING: JNI method called with exception pending
    05-03 19:07:57.186: W/dalvikvm(1837): in Lcom/giderosmobile/android/player/GiderosApplication;.nativeDrawFrame:()V (GetStaticMethodID)
    05-03 19:07:57.186: W/dalvikvm(1837): Pending exception is:
    05-03 19:07:57.186: I/dalvikvm(1837): java.lang.NullPointerException:
    05-03 19:07:57.186: I/dalvikvm(1837): at com.giderosmobile.android.plugins.facebook.GFacebook.getFBToken(GFacebook.java:148)
    05-03 19:07:57.186: I/dalvikvm(1837): at com.giderosmobile.android.plugins.facebook.GFacebook.setAppId(GFacebook.java:57)
    05-03 19:07:57.186: I/dalvikvm(1837): at com.giderosmobile.android.player.GiderosApplication.nativeDrawFrame(Native Method)
    05-03 19:07:57.186: I/dalvikvm(1837): at com.giderosmobile.android.player.GiderosApplication.onDrawFrame(GiderosApplication.java:460)
    05-03 19:07:57.186: I/dalvikvm(1837): at com.giderosmobile.android.GiderosRenderer.onDrawFrame(FacebookTestActivity.java:220)
    05-03 19:07:57.186: I/dalvikvm(1837): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1516)
    05-03 19:07:57.186: I/dalvikvm(1837): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
    05-03 19:07:57.186: I/dalvikvm(1837): "GLThread 99" prio=5 tid=11 NATIVE
    05-03 19:07:57.186: I/dalvikvm(1837): | group="main" sCount=0 dsCount=0 obj=0x40cefd78 self=0x2a1aa890
    05-03 19:07:57.186: I/dalvikvm(1837): | sysTid=1851 nice=0 sched=0/0 cgrp=apps handle=705983240
    05-03 19:07:57.194: I/dalvikvm(1837): | state=R schedstat=( 1554928830 3867307252 625 ) utm=136 stm=19 core=0
    05-03 19:07:57.214: I/dalvikvm(1837): #00 pc 000012a0 /system/lib/libcorkscrew.so (unwind_backtrace_thread+27)
    05-03 19:07:57.214: I/dalvikvm(1837): #01 pc 0005faa8 /system/lib/libdvm.so (dvmDumpNativeStack(DebugOutputTarget const*, int)+35)
    05-03 19:07:57.214: I/dalvikvm(1837): #02 pc 00053914 /system/lib/libdvm.so (dvmDumpThreadEx(DebugOutputTarget const*, Thread*, bool)+303)
    05-03 19:07:57.214: I/dalvikvm(1837): #03 pc 000539ae /system/lib/libdvm.so (dvmDumpThread(Thread*, bool)+25)
    05-03 19:07:57.214: I/dalvikvm(1837): #04 pc 00038aba /system/lib/libdvm.so
    05-03 19:07:57.214: I/dalvikvm(1837): #05 pc 0003df2e /system/lib/libdvm.so
    05-03 19:07:57.214: I/dalvikvm(1837): #06 pc 000095e4 /data/app-lib/com.flipfloplab.facebooktest-2/libfacebook.so (gfacebook_authorize+284)
    05-03 19:07:57.214: I/dalvikvm(1837): #07 pc 0000801c /data/app-lib/com.flipfloplab.facebooktest-2/libfacebook.so
    05-03 19:07:57.214: I/dalvikvm(1837): #08 pc 0011776c /data/app-lib/com.flipfloplab.facebooktest-2/libgideros.so
    05-03 19:07:57.224: I/dalvikvm(1837): #09 pc 00116aac /data/app-lib/com.flipfloplab.facebooktest-2/libgideros.so
    05-03 19:07:57.224: I/dalvikvm(1837): #10 pc 001171ba /data/app-lib/com.flipfloplab.facebooktest-2/libgideros.so
    05-03 19:07:57.224: I/dalvikvm(1837): #11 pc 00118376 /data/app-lib/com.flipfloplab.facebooktest-2/libgideros.so (lua_call+13)
    05-03 19:07:57.224: I/dalvikvm(1837): #12 pc 00144b3a /data/app-lib/com.flipfloplab.facebooktest-2/libgideros.so
    05-03 19:07:57.224: I/dalvikvm(1837): #13 pc 0011776c /data/app-lib/com.flipfloplab.facebooktest-2/libgideros.so
    05-03 19:07:57.224: I/dalvikvm(1837): #14 pc 00117190 /data/app-lib/com.flipfloplab.facebooktest-2/libgideros.so
    05-03 19:07:57.224: I/dalvikvm(1837): #15 pc 00112ea8 /data/app-lib/com.flipfloplab.facebooktest-2/libgideros.so
    05-03 19:07:57.224: I/dalvikvm(1837): #16 pc 00112ea8 /data/app-lib/com.flipfloplab.facebooktest-2/libgideros.so
    05-03 19:07:57.224: I/dalvikvm(1837): #17 pc 00112ea8 /data/app-lib/com.flipfloplab.facebooktest-2/libgideros.so
    05-03 19:07:57.224: I/dalvikvm(1837): #18 pc 00112ea8 /data/app-lib/com.flipfloplab.facebooktest-2/libgideros.so
    05-03 19:07:57.224: I/dalvikvm(1837): #19 pc 00112ea8 /data/app-lib/com.flipfloplab.facebooktest-2/libgideros.so
    05-03 19:07:57.224: I/dalvikvm(1837): #20 pc 00112ea8 /data/app-lib/com.flipfloplab.facebooktest-2/libgideros.so
    05-03 19:07:57.224: I/dalvikvm(1837): #21 pc 00112ea8 /data/app-lib/com.flipfloplab.facebooktest-2/libgideros.so
    05-03 19:07:57.224: I/dalvikvm(1837): #22 pc 00112ea8 /data/app-lib/com.flipfloplab.facebooktest-2/libgideros.so
    05-03 19:07:57.224: I/dalvikvm(1837): #23 pc 00112ea8 /data/app-lib/com.flipfloplab.facebooktest-2/libgideros.so
    05-03 19:07:57.224: I/dalvikvm(1837): #24 pc 00112ea8 /data/app-lib/com.flipfloplab.facebooktest-2/libgideros.so
    05-03 19:07:57.224: I/dalvikvm(1837): #25 pc 00112ea8 /data/app-lib/com.flipfloplab.facebooktest-2/libgideros.so
    05-03 19:07:57.224: I/dalvikvm(1837): #26 pc 00112ea8 /data/app-lib/com.flipfloplab.facebooktest-2/libgideros.so
    05-03 19:07:57.224: I/dalvikvm(1837): #27 pc 00112ea8 /data/app-lib/com.flipfloplab.facebooktest-2/libgideros.so
    05-03 19:07:57.224: I/dalvikvm(1837): #28 pc 00112ea8 /data/app-lib/com.flipfloplab.facebooktest-2/libgideros.so
    05-03 19:07:57.224: I/dalvikvm(1837): #29 pc 00112ea8 /data/app-lib/com.flipfloplab.facebooktest-2/libgideros.so
    05-03 19:07:57.224: I/dalvikvm(1837): #30 pc 00112ea8 /data/app-lib/com.flipfloplab.facebooktest-2/libgideros.so
    05-03 19:07:57.234: I/dalvikvm(1837): #31 pc 00112ea8 /data/app-lib/com.flipfloplab.facebooktest-2/libgideros.so
    05-03 19:07:57.234: I/dalvikvm(1837): at com.giderosmobile.android.player.GiderosApplication.nativeDrawFrame(Native Method)
    05-03 19:07:57.234: I/dalvikvm(1837): at com.giderosmobile.android.player.GiderosApplication.onDrawFrame(GiderosApplication.java:460)
    05-03 19:07:57.234: I/dalvikvm(1837): at com.giderosmobile.android.GiderosRenderer.onDrawFrame(FacebookTestActivity.java:220)
    05-03 19:07:57.234: I/dalvikvm(1837): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1516)
    05-03 19:07:57.234: I/dalvikvm(1837): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
    05-03 19:07:57.234: E/dalvikvm(1837): VM aborting
    05-03 19:07:57.234: A/libc(1837): Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1), thread 1851 (Thread-99)

  • ar2rsawseenar2rsawseen +1 -1
    Hmm, thats strange the line NullPointer exception is pointing to is a quite harmless line:
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(sActivity.get());

    So unless there is a reason I'm not aware of, where shared preferences are not available, I can't really think of a reason.
    What device are you trying it on? Model, OS version, etc
  • Emanuel +1 -1
    I tested on two ... galaxy s3 4.1.2 and 4.2.2 emulator
  • Emanuel +1 -1
    the same problem in both
  • ar2rsawseenar2rsawseen +1 -1
    Hmm, can't really reproduce.

    If you comment out the line 57:
    String token = getFBToken();

    in src/com/giderosmobile/android/plugins/facebook/GFacebook.java

    and replace it with this line:
    String token = "";

    Do you have any other problems then?
  • Emanuel +1 -1
    now opens and close after....

  • ar2rsawseenar2rsawseen +1 -1
    @Emanuel, can you send me your Android project? Like attach here on the forum or send by email to ar2rsawseen at gmail dot com
    Just so I could check that everything is set up normally? :)
  • Emanuel +1 -1
    Please tell me what you changed ... ok thank you
  • @Emanuel is my friend...tks for help @ar2rsawseen you awesome
  • ar2rsawseenar2rsawseen +1 -1
    Hello @Emanuel ;)

    I've tried your project, but it does not have facebook plugin installed at all.

    You need to copy .so files, copy .java files and modify main activity like it's told here:
  • Emanuel +1 -1
    Sorry, I sent the wrong file ....
  • Emanuel +1 -1
    This is all done and the problem that I reported ...
  • ar2rsawseenar2rsawseen +1 -1
    @Emanuel it seems that you forgot to add GFacebook class to external classes in main Activity like this:
    static private String[] externalClasses = {

    You should of course also modify the GFacebook class back as it was ;)
  • Emanuel +1 -1
    Thank you. worked!!
  • Emanuel +1 -1
    @ar2rsawseen when you translate facebook plugin for android to facebook 3.0.1 sdk version?
  • ar2rsawseenar2rsawseen +1 -1
    @Emanuel unfortunately the problem is, that Facebook SDK v3 is completely different, and current Gideros Facebook API (which is based on Facebook SDK v2) is completely incompatible with Facebook SDK v3.
    1) it would break existing apps
    2) there is a need of time and workforce to do that, both now are dedicated to more urgent matters

    But that might change if someone is willing to wrap Facebook SDK in Java and IOS wrappers with similar API to current :)
  • Emanuel +1 -1
    @ar2rsaween do you have facebook sdk v2 to send me, because I dont found to download. My email emanuelperpeto @ gmail dot com
  • ar2rsawseenar2rsawseen +1 -1
    @Emanuel last time I checked Facebook SDK v3 also includes deprecated v2 methods, so it should work with it. Sorry if I did not make it clear :)
  • fxonefxone +1 -1
    I have some issue with FB @ar2rsawseen's plugin integration at Android device. Under Eclipse everything looks fine, there is no errors. I can sign apk properly, I can also install apk on device, with no problem. But:
    - Just after running app with @ar2rsawseen's default example, when it's trying to connect with fb, I have an info about error: "Invalid android key parameter. The key [there is a key 28 chars] does not match any allowed key...[!]
    honestly I have six variations of these keys: with "=" on the end, from 28 to 31 chars etc... followed by different advices like for example from here:
    I have now 8 various hash keys and I'm going crazy @-) - I've spent already 12 hours on it... Please help me!
    Windows 7 x64 /Android 2.2 Froyo.

    ps. of course I've changed appId..
  • ar2rsawseenar2rsawseen +1 -1 (+1 / -0 )
    @fxone I used this code to check what has key really was:
    only replace it with your package name
    PackageInfo info;
    try {
    info = sActivity.get().getPackageManager().getPackageInfo("com.yourdomain.yourapp", PackageManager.GET_SIGNATURES);
    for (Signature signature : info.signatures) {
    MessageDigest md;
    md = MessageDigest.getInstance("SHA");
    String something = new String(Base64.encode(md.digest(), 0));
    //String something = new String(Base64.encodeBytes(md.digest()));
    Log.e("hash key", something);
    } catch (NameNotFoundException e1) {
    Log.e("name not found", e1.toString());
    } catch (NoSuchAlgorithmException e) {
    Log.e("no such an algorithm", e.toString());
    } catch (Exception e) {
    Log.e("exception", e.toString());

    and then you should input this hash key in the facebook.com in your Android app settings.

    Likes: fxone

  • fxonefxone +1 -1
    @ar2rsawseen Thanks! ok finally full success: it was one from my eight key hashes, but unfortunately I set too much on fb site yesterday evening :D it also works properly for me: http://stackoverflow.com/a/7564008
  • fxonefxone +1 -1
    Hi @ar2rsawseen! Ok finally I can post and get scores, feeds to fb etc. But I've noticed some problem: when I beat a record during one session, it's received some error in lua:
    start.lua:48: attempt to index field 't' (a boolean value)
    stack traceback:
    start.lua:48: in function <start.lua:26>

    in start.lua my code looks like:
    if facebook:isSessionValid() then
    local t = Json.Decode(event.response)
    local Text = TextField.new(nil, "You have"..t.data[1].score.." scores!")

    There is no error at first attempt of:
    only at second when I change the scene from level.lua to start.lua page only after posting a new record..

    thanks in advance!

  • ar2rsawseenar2rsawseen +1 -1 (+1 / -0 )
    @fxone could you please tell me what are the contents of event.response after second request?

    Likes: fxone

  • fxonefxone +1 -1
    @ar2rsawseen right, second request from level.lua:
    	if facebook:isSessionValid() then
    print("Send score to facebook "..score)
    local parameters = {
    score = score,
    fields = "firstname"
    facebook:graphRequest("me/scores", parameters,"POST")
    local response=Json.Decode(event.response)
    print("event response", response)

    ps. ok I got it one sec... :)
  • fxonefxone +1 -1
    @ar2rsawseen contents of event.response after second request from level.lua (as above) is:
    [edited Sorry, I've checked again]
    event response nil

    event response true ...

  • fxonefxone +1 -1
    @ar2rsawseen is this a bug? similiar to: http://stackoverflow.com/questions/15988268/calling-functions-on-required-modules-in-lua-gives-me-attempt-to-index-local
    I've tried also some Corona solution, looking like (firstly removed
    from top):
    local json=require("Json") 
    local t=json.Decode(event.response)

    but it's still the same:
    attempt to index field 't' (a boolean value)I know, it's too late :) Let's get back on track tomorrow! ;)
  • fxonefxone +1 -1
    @ar2rsawseen sorry for annoying asking since yesterday, but is this possible to remove listeners for:
    from facebook plugin? It looks like it holds value and ignores new attempt of request...
  • ar2rsawseenar2rsawseen +1 -1 (+1 / -0 )
    @fxone yes, basically what happens is that retrieving score returns json with all the data, but submitting score returns value true.
    So what you would need to do is to expect any kind of result. Probably the easiest way is to check
    if e.response ~= "true" then
    local t = Json.Decode(e.response)
    if t.data then
    --have your score result here
    elseif e.response == "false" then
    --could not submit the score

    Unfortunately there is no direct way to determine to which app requests we got the response for, at least current Facebook SKD does not provide it. So your best bet is to try to determine it based on the contents of response.

    So right now there is only one REQUEST_COMPLETE event and you should try to combine everything in one event call if you can, like here handling both retrieving and submitting scores.

    Likes: fxone

  • fxonefxone +1 -1
    @ar2rsawseen you are great! :-bd I got stuck, but finally it solved, thank you! it's working like a charm now :D
  • Hi all,

    Help Please !!.. ive been staring at this for hours, ive followed the facebook setup, and imported and removed the Facebook SDK a few times as i cant get rid of these errors.

    i have 2 screen shots showing each of the SDK projects with errors, and the build path looks ok.

    also the reference to "GFacebook.fb.authorizeCallback(requestCode, resultCode, data);" has an error on "GFacebook".

    Pleaseeee im running out of the bits of hair i had left.

  • ar2rsawseenar2rsawseen +1 -1
    @ArtLeeApps have you imported com.giderosmobile.android.plugins.facebook.GFacebook into your main activity? :)

    I found that it also seemed to work when both Facebook SDK and your Gideros Facebook project folders are in the same workspace (basically in the same relative folder)

    You must not add facebooksdk.jar but rather treat whole FacebookSDK project as a library and install it as described in installation instructions. As far as I know there are no more simple .jar files in facebook
  • ar2rsawseenar2rsawseen +1 -1
    I've also attached Facebook SDK I used to develop plugin to the first post and I'm pushing it to github
  • @ar2rsawseen thank you,
    in the process of adding Facebook i imported the folder into my app, resulting in the facebook stuff overwriting the manifest and stuff.. so ive just done a full Gideros export, re-added, AdMob, Billing, and Facebook.. (and made notes on what i did )

    Anyway, after moving the Facebook SDK folders to my workspace, and then importing that into eclipse, then added it as a Library to my project it was happy.
    all the sample facebook apps had issues, but i worked out, i had to add (android-support-v4.jar) as an external Jar to make them happy too :)

    now its 2am here in the land of OZ so ill start trying to setup the bits to get my Facebook APP ID tommorrow, so i can post from my app... finally !

    Thanks again :-bd
  • Hi @ar2rsawseen

    When the code get to the "Authorize()"
    it goes to a Web page not found.
    and eclipse has this in the logs.....

    08-05 21:55:47.642: W/dalvikvm(16663): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
    08-05 21:55:47.642: W/dalvikvm(16663): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
    08-05 21:55:47.652: I/dalvikvm(16663): Could not find method android.support.v4.content.LocalBroadcastManager.getInstance, referenced from method com.facebook.Session.postActiveSessionAction
    08-05 21:55:47.652: W/dalvikvm(16663): VFY: unable to resolve static method 360: Landroid/support/v4/content/LocalBroadcastManager;.getInstance (Landroid/content/Context;)Landroid/support/v4/content/LocalBroadcastManager;
    08-05 21:55:47.652: D/dalvikvm(16663): VFY: replacing opcode 0x71 at 0x0009
    08-05 21:55:47.652: D/dalvikvm(16663): VFY: dead code 0x000c-0010 in Lcom/facebook/Session;.postActiveSessionAction (Ljava/lang/String;)V
    08-05 21:55:47.812: D/dalvikvm(16663): GC_CONCURRENT freed 618K, 46% free 3483K/6407K, external 2K/514K, paused 3ms+11ms
    08-05 21:55:47.852: D/MediaPlayer(16663): pause() in
    08-05 21:55:47.862: D/MediaPlayer(16663): pause() out
    08-05 21:55:47.872: D/AudioTrack(16663): Audio Track already stopped

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Login with Facebook Sign In with OpenID

In this Discussion

Top Posters