Facebook Plugin problems

Hi,
I’m trying to implement the Facebook SDK in my App, and i’m evaluating to use sdkbox. I read the methods that sdkbox offer for facebook.
But I have this problems:

1- How can I get the user first and last name in facebook? I only see the method getUserId(). Anyone have any example?

2- How can I add a “Like” button to a Facebook-page? I read this page: https://developers.facebook.com/docs/sharing/ios/like-button/ but can I do that with sdkbox? The code that’s facebook offer is in Objetive-C and i’m developing in c++.

3- The method sdkbox::PluginFacebook::inviteFriends does not work. When I call it, it works, I can select friends in a friend list but when I want to send the invitations, the app crashes. I think the problem is that I have a Facebook App but the invitations opens in Facebook Browser. I read this topic, but I don’t understand the solution: [SOLVED] SDKBOX Facebook InviteFriends not working

Anyone can help me?
Thanks

you can get all info in onGetUserInfo( const sdkbox::FBGraphUser& userInfo ) callback . https://github.com/sdkbox/sdkbox-sample-facebook/blob/master/cpp/Classes/HelloWorldScene.cpp#L817

sdkbox don’t support like feature.

can you show the crash log ?

@yinjimmy thanks for the answer.
Respect to the first point. My listener does not work.
In AppDelegate.cpp (method applicationDidFinishLaunching) I add this code:

#ifdef SDKBOX_ENABLED
    sdkbox::PluginFacebook::setListener(FacebookHandler::getInstance());
    sdkbox::PluginFacebook::init();
#endif

This is my FacebookHandler class:

class FacebookHandler : public sdkbox::FacebookListener
{
public:
    FacebookHandler();
    ~FacebookHandler();
     static FacebookHandler* getInstance();
    
    void onGetUserInfo(const sdkbox::FBGraphUser &userInfo);
};

Methods:

FacebookHandler::FacebookHandler()
{
}

FacebookHandler* FacebookHandler::getInstance()
{
    static FacebookHandler *sharedInstance;
    return sharedInstance;
}

void FacebookHandler::onGetUserInfo(const sdkbox::FBGraphUser &userInfo)
{
    log("Facebook id:'%s' name:'%s' last_name:'%s' first_name:'%s' email:'%s' installed:'%d'",
          userInfo.getUserId().c_str(),
          userInfo.getName().c_str(),
          userInfo.getFirstName().c_str(),
          userInfo.getLastName().c_str(),
          userInfo.getEmail().c_str(),
          userInfo.isInstalled ? 1 : 0
          );
}

FacebookHandler::~FacebookHandler()
{
}

However, when I log in to Facebook, the framework does not call automatically onGetUserInfo. What is my problem?

I debugged it. This is the log when the compiler execute setListener method.

2017-09-14 19:36:03.725980-0300 MyCppGame-mobile[15478:5307448] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2017-09-14 19:36:03.728194-0300 MyCppGame-mobile[15478:5307448] [MC] Reading from public effective user settings.

After that, compile the init method and the follow code in AppDelegate. This is the log:

2017-09-14 19:37:10.427545-0300 MyCppGame-mobile[15478:5307448] FBSDKLog: FBSDKTimeSpentData Restore: {"lastSuspendTime":1505353777,"numInterruptions":2,"sessionID":"7CCE0CA7-97F7-4612-A14D-F887205B7646","secondsSpentInCurrentSession":3}
2017-09-14 19:37:10.429198-0300 MyCppGame-mobile[15478:5307448] FBSDKLog: FBSDKAppEvents: Recording event @ 1505428630: {
    "_eventName" = "fb_mobile_deactivate_app";
    "_logTime" = 1505353777;
    "_session_id" = "7CCE0CA7-97F7-4612-A14D-F887205B7646";
    "_ui" = "no_ui";
    "_valueToSum" = 3;
    "fb_mobile_app_interruptions" = 2;
    "fb_mobile_launch_source" = Unclassified;
    "fb_mobile_time_between_sessions" = "session_quanta_6";
}
2017-09-14 19:37:10.429998-0300 MyCppGame-mobile[15478:5307448] FBSDKLog: FBSDKAppEvents Persist: Read 0 event states. First state has 0 events
2017-09-14 19:37:10.430090-0300 MyCppGame-mobile[15478:5307448] FBSDKLog: FBSDKAppEvents Persist: Clearing
2017-09-14 19:37:10.431600-0300 MyCppGame-mobile[15478:5307448] FBSDKLog: FBSDKAppEvents: Recording event @ 1505428630: {
    "_eventName" = "fb_mobile_activate_app";
    "_logTime" = 1505428630;
    "_session_id" = "10201322-4FD3-41B9-AFA2-259A29841BB1";
    "_ui" = "no_ui";
    "fb_mobile_launch_source" = Unclassified;
}
2017-09-14 19:37:10.433684-0300 MyCppGame-mobile[15478:5307448] #### ACTIVE
2017-09-14 19:37:10.438306-0300 MyCppGame-mobile[15478:5307448] cocos2d: surface size: 640x1136
2017-09-14 19:37:10.449221-0300 MyCppGame-mobile[15478:5307448] cocos2d: surface size: 640x1136
2017-09-14 19:37:11.029013-0300 MyCppGame-mobile[15478:5307448] FBSDKLog: FBSDKAppEvents: Flushed @ 1505428631, 2 events due to 'EagerlyFlushingEvent' - {
    "advertiser_id" = "FEC1AFC1-A366-4B1B-BFDC-BC7514B5E0DF";
    "advertiser_tracking_enabled" = 1;
    "anon_id" = "XZE3203852-BCCC-4922-8832-64ABD2815B06";
    "application_tracking_enabled" = 1;
    event = "CUSTOM_APP_EVENTS";
    extinfo = "[\"i2\",\"com.gamefromscratch.gamename18\",\"1.0\",\"\",\"10.3.3\",\"iPhone9,3\",\"es_US\",\"GMT-3\",\"Carrier\",320,568,\"2.00\",2,30,5,\"America\\/Buenos_Aires\"]";
    "url_schemes" = "[\"fb2045915002286566\",\"powBox\"]";
}
Events: [
  {
    "event" : {
      "fb_mobile_time_between_sessions" : "session_quanta_6",
      "_eventName" : "fb_mobile_deactivate_app",
      "fb_mobile_launch_source" : "Unclassified",
      "_logTime" : 1505353777,
      "_session_id" : "7CCE0CA7-97F7-4612-A14D-F887205B7646",
      "fb_mobile_app_interruptions" : 2,
      "_ui" : "no_ui",
      "_valueToSum" : 3
    },
    "isImplicit" : false
  },
  {
    "event" : {
      "_ui" : "no_ui",
      "_eventName" : "fb_mobile_activate_app",
      "_logTime" : 1505428630,
      "_session_id" : "10201322-4FD3-41B9-AFA2-259A29841BB1",
      "fb_mobile_launch_source" : "Unclassified"
    },
    "isImplicit" : false
  }
]
Flush Result : Success

Then, I log in to facebook in my Game class.
Code:

sdkbox::PluginFacebook::logout();
if(sdkbox::PluginFacebook::isLoggedIn() == false)
sdkbox::PluginFacebook::requestReadPermissions({sdkbox::FB_PERM_READ_PUBLIC_PROFILE, sdkbox::FB_PERM_READ_USER_FRIENDS}); 

This is the log after log in:

2017-09-14 19:38:59.082357-0300 MyCppGame-mobile[15478:5307448] FBSDKLog: FBSDKAppEvents: Flushed @ 1505428739, 2 events due to 'Timer' - {
    "advertiser_tracking_enabled" = 1;
    "anon_id" = "XZE3203852-BCCC-4922-8832-64ABD2815B06";
    "application_tracking_enabled" = 1;
    event = "CUSTOM_APP_EVENTS";
    extinfo = "[\"i2\",\"com.gamefromscratch.gamename18\",\"1.0\",\"\",\"10.3.3\",\"iPhone9,3\",\"es_US\",\"GMT-3\",\"Carrier\",320,568,\"2.00\",2,30,5,\"America\\/Buenos_Aires\"]";
    "url_schemes" = "[\"fb2045915002286566\",\"powBox\"]";
}
Events: [
  {
    "event" : {
      "4_error_code" : "",
      "_implicitlyLogged" : "1",
      "7_logging_token" : "",
      "_eventName" : "fb_mobile_login_start",
      "_logTime" : 1505428735,
      "1_timestamp_ms" : 1505428734833,
      "6_extras" : "{\"default_audience\":\"friends\",\"tryIntegratedAuth\":false,\"tryFBAppAuth\":true,\"login_behavior\":\"FBSDKLoginBehaviorNative\",\"tryFallback\":false,\"permissions\":\"public_profile,user_friends\",\"trySafariAuth\":true,\"isReauthorize\":false}",
      "_ui" : "no_ui",
      "5_error_message" : "",
      "2_result" : "",
      "0_auth_logger_id" : "59EBB84A-1C45-427E-AE64-B20D474CA88E"
    },
    "isImplicit" : true
  },
  {
    "event" : {
      "0_auth_logger_id" : "59EBB84A-1C45-427E-AE64-B20D474CA88E",
      "3_method" : "sfvc_auth",
      "1_timestamp_ms" : 1505428734973,
      "_ui" : "FBSDKContainerViewController",
      "7_logging_token" : "",
      "_logTime" : 1505428735,
      "4_error_code" : "",
      "_implicitlyLogged" : "1",
      "6_extras" : "{\"isMessengerAppCanOpenURLSchemeRegistered\":false,\"isURLSchemeRegistered\":true,\"isFacebookAppCanOpenURLSchemeRegistered\":true}",
      "2_result" : "",
      "_eventName" : "fb_mobile_login_method_start",
      "5_error_message" : ""
    },
    "isImplicit" : true
  }
]
Flush Result : Success



017-09-14 19:39:28.119596-0300 MyCppGame-mobile[15478:5307448] FBSDKLog: FBSDKTimeSpentData Restore: {"lastSuspendTime":1505428759,"numInterruptions":0,"sessionID":"10201322-4FD3-41B9-AFA2-259A29841BB1","secondsSpentInCurrentSession":129}
2017-09-14 19:39:28.120139-0300 MyCppGame-mobile[15478:5307448] #### ACTIVE
2017-09-14 19:39:28.688460-0300 MyCppGame-mobile[15478:5307448] FBSDKLog: The app tried to call version v2.8. This app can only call versions v2.10 and higher, so the request defaulted to version v2.10. Link: https://developers.facebook.com/docs/apps/versions/
2017-09-14 19:39:28.688514-0300 MyCppGame-mobile[15478:5307448] FBSDKLog: The field 'email' is only accessible on the User object after the user grants the 'email' permission.
2017-09-14 19:39:41.084331-0300 MyCppGame-mobile[15478:5307448] FBSDKLog: FBSDKAppEvents: Flushed @ 1505428780, 2 events due to 'Timer' - {
    "advertiser_tracking_enabled" = 1;
    "anon_id" = "XZE3203852-BCCC-4922-8832-64ABD2815B06";
    "application_tracking_enabled" = 1;
    event = "CUSTOM_APP_EVENTS";
    extinfo = "[\"i2\",\"com.gamefromscratch.gamename18\",\"1.0\",\"\",\"10.3.3\",\"iPhone9,3\",\"es_US\",\"GMT-3\",\"Carrier\",320,568,\"2.00\",2,30,5,\"America\\/Buenos_Aires\"]";
    "url_schemes" = "[\"fb2045915002286566\",\"powBox\"]";
}
Events: [
  {
    "event" : {
      "0_auth_logger_id" : "59EBB84A-1C45-427E-AE64-B20D474CA88E",
      "3_method" : "sfvc_auth",
      "1_timestamp_ms" : 1505428767706,
      "_ui" : "no_ui",
      "7_logging_token" : "",
      "_logTime" : 1505428768,
      "4_error_code" : "",
      "_implicitlyLogged" : "1",
      "6_extras" : "{}",
      "2_result" : "success",
      "_eventName" : "fb_mobile_login_method_complete",
      "5_error_message" : ""
    },
    "isImplicit" : true
  },
  {
    "event" : {
      "0_auth_logger_id" : "59EBB84A-1C45-427E-AE64-B20D474CA88E",
      "3_method" : "sfvc_auth",
      "1_timestamp_ms" : 1505428767707,
      "_ui" : "no_ui",
      "7_logging_token" : "",
      "_logTime" : 1505428768,
      "4_error_code" : "",
      "_implicitlyLogged" : "1",
      "6_extras" : "{}",
      "2_result" : "success",
      "_eventName" : "fb_mobile_login_complete",
      "5_error_message" : ""
    },
    "isImplicit" : true
  }
]
Flush Result : Success

However, the method onGetUserInfo is never called.

**

Respect to the second point.

The sdkbox team plans to add Like button? Despite of not have it, how can I add it? is there an easy way to implement the code here? https://developers.facebook.com/docs/sharing/ios/like-button/

Respect to the last point. This is the log:

2017-09-14 20:05:29.603077-0300 MyCppGame-mobile[15494:5311066] FBSDKLog: FBSDKAppEvents: Flushed @ 1505430329, 1 events due to 'Timer' - {
    "advertiser_tracking_enabled" = 1;
    "anon_id" = "XZE3203852-BCCC-4922-8832-64ABD2815B06";
    "application_tracking_enabled" = 1;
    event = "CUSTOM_APP_EVENTS";
    extinfo = "[\"i2\",\"com.gamefromscratch.gamename18\",\"1.0\",\"\",\"10.3.3\",\"iPhone9,3\",\"es_US\",\"GMT-3\",\"Carrier\",320,568,\"2.00\",2,30,5,\"America\\/Buenos_Aires\"]";
    "url_schemes" = "[\"fb2045915002286566\",\"powBox\"]";
}
Events: [
  {
    "event" : {
      "_eventName" : "fb_app_invite_share_show",
      "_logTime" : 1505430329,
      "_implicitlyLogged" : "1",
      "_ui" : "no_ui"
    },
    "isImplicit" : true
  }
]
Flush Result : Success

.
.
.
.


ACS031006] View controller already tracked. Class, ID: FBSDKContainerViewController, 3088785018862332402
2017-09-14 20:07:10.273975-0300 MyCppGame-mobile[15494:5311231] [Firebase/Analytics][I-ACS031006] View controller already tracked. Class, ID: FBSDKContainerViewController, 3088785018862332402
2017-09-14 20:07:10.274 MyCppGame-mobile[15494] <Debug> [Firebase/Analytics][I-ACS031006] View controller already tracked. Class, ID: FBSDKContainerViewController, 3088785018862332402
2017-09-14 20:07:10.274155-0300 MyCppGame-mobile[15494:5311231] [Firebase/Analytics][I-ACS031006] View controller already tracked. Class, ID: FBSDKContainerViewController, 3088785018862332402
2017-09-14 20:07:10.274 MyCppGame-mobile[15494] <Debug> [Firebase/Analytics][I-ACS031006] View controller already tracked. Class, ID: FBSDKContainerViewController, 3088785018862332402
MyCppGame-mobile was compiled with optimization - stepping may behave oddly; variables may not be available.

It crashes in an assembler instruction.

    static FacebookHandler *sharedInstance = NULL;
    if (sharedInstance == NULL) sharedInstance = new FacebookHandler();

I have an error in this line:
sharedInstance = new FacebookHandler();

Allocating an object of abstract class type 'FacebookHandler'

edit RootViewController.mm file

- (void)viewDidLoad {
    [super viewDidLoad];

    FBSDKLikeControl *likeButton = [[FBSDKLikeControl alloc] init];
    likeButton.objectID = @"https://www.facebook.com/FacebookDevelopers";
    likeButton.center = self.view.center;
    [self.view addSubview:likeButton];
    [likeButton setHidden:YES];

    auto dispatcher = cocos2d::Director::getInstance()->getEventDispatcher();
    dispatcher->addCustomEventListener("show_like_btn", [&, likeButton](cocos2d::EventCustom*) {
        [likeButton setHidden:NO];
    });
    dispatcher->addCustomEventListener("hide_like_btn", [&, likeButton](cocos2d::EventCustom*) {
        [likeButton setHidden:NO];
    });

    // how to use
//    dispatcher->dispatchCustomEvent("show_like_btn");
//    dispatcher->dispatchCustomEvent("hide_like_btn");
}

should incomplete all these functions in your FacebookHandler class.

        virtual void onLogin(bool isLogin, const std::string& msg) = 0;
        virtual void onSharedSuccess(const std::string& message) = 0;
        virtual void onSharedFailed(const std::string& message) = 0;
        virtual void onSharedCancel() = 0;
        virtual void onAPI(const std::string& key, const std::string& jsonData) = 0;
        virtual void onPermission(bool isLogin, const std::string& msg) = 0;
        virtual void onFetchFriends(bool ok, const std::string& msg) = 0;
        virtual void onRequestInvitableFriends( const FBInvitableFriendsInfo& friends ) = 0;
        virtual void onInviteFriendsWithInviteIdsResult( bool result, const std::string& msg )= 0;
        virtual void onInviteFriendsResult( bool result, const std::string& msg )= 0;

        virtual void onGetUserInfo( const FBGraphUser& userInfo ) = 0;

How is the final class?
I continue with the same error in the line sharedInstance = new FacebookHandler();

This is my class:

class FacebookHandler : public sdkbox::FacebookListener
{
public:
    FacebookHandler();
    ~FacebookHandler();
    static FacebookHandler* getInstance();
    
    virtual void onLogin(bool isLogin, const std::string& msg) = 0;
    virtual void onSharedSuccess(const std::string& message) = 0;
    virtual void onSharedFailed(const std::string& message) = 0;
    virtual void onSharedCancel() = 0;
    virtual void onAPI(const std::string& key, const std::string& jsonData) = 0;
    virtual void onPermission(bool isLogin, const std::string& msg) = 0;
    virtual void onFetchFriends(bool ok, const std::string& msg) = 0;
    virtual void onRequestInvitableFriends( const sdkbox::FBInvitableFriendsInfo& friends ) = 0;
    virtual void onInviteFriendsWithInviteIdsResult( bool result, const std::string& msg )= 0;
    virtual void onInviteFriendsResult( bool result, const std::string& msg )= 0;
    virtual void onGetUserInfo( const sdkbox::FBGraphUser& userInfo ) = 0;
};

cpp:

FacebookHandler::FacebookHandler()
{
}

FacebookHandler* FacebookHandler::getInstance()
{
    static FacebookHandler *sharedInstance = NULL;
    if (sharedInstance == NULL)
        sharedInstance = new FacebookHandler();
}

void FacebookHandler::onGetUserInfo(const sdkbox::FBGraphUser &userInfo)
{
    log("Facebook id:'%s' name:'%s' last_name:'%s' first_name:'%s' email:'%s' installed:'%d'",
          userInfo.getUserId().c_str(),
          userInfo.getName().c_str(),
          userInfo.getFirstName().c_str(),
          userInfo.getLastName().c_str(),
          userInfo.getEmail().c_str(),
          userInfo.isInstalled ? 1 : 0
          );
}

FacebookHandler::~FacebookHandler()
{
}

virtual void onLogin(bool isLogin, const std::string& msg) {}

I continue with the same error :frowning:

class FacebookHandler : public sdkbox::FacebookListener
{
public:
    FacebookHandler();
    ~FacebookHandler();
    static FacebookHandler* getInstance();
    
    virtual void onLogin(bool isLogin, const std::string& msg) {}
    virtual void onSharedSuccess(const std::string& message) {}
    virtual void onSharedFailed(const std::string& message) {}
    virtual void onSharedCancel() {}
    virtual void onAPI(const std::string& key, const std::string& jsonData) {}
    virtual void onPermission(bool isLogin, const std::string& msg) {}
    virtual void onFetchFriends(bool ok, const std::string& msg) {}
    virtual void onRequestInvitableFriends( const sdkbox::FBInvitableFriendsInfo& friends ) {}
    virtual void onInviteFriendsWithInviteIdsResult( bool result, const std::string& msg ) {}
    virtual void onInviteFriendsResult( bool result, const std::string& msg ) {}

    virtual void onGetUserInfo( const sdkbox::FBGraphUser& userInfo );
};

@yinjimmy thanks for your help, and sorry for my ignorance!
Now, It works fine. But I discovered a problem.

If I call this method:
sdkbox::PluginFacebook::requestReadPermissions({sdkbox::FB_PERM_READ_PUBLIC_PROFILE, sdkbox::FB_PERM_READ_USER_FRIENDS});

onLogin and onGetUserInfo callbacks does not work. But if I call this method:

std::vector<std::string> permissions;
permissions.push_back(sdkbox::FB_PERM_READ_PUBLIC_PROFILE);
permissions.push_back(sdkbox::FB_PERM_READ_USER_FRIENDS);
sdkbox::PluginFacebook::login(permissions);

The callbacks works fine. Maybe it is a sdkbox bug?

Respect to the second point.
I followed your steps. But I have a question.
When I add this line to my class:

Director::getInstance()->getEventDispatcher()->dispatchCustomEvent("show_like_btn");

It works fine, this is the log:

Events: [
  {
    "event" : {
      "horizontal_alignment" : "left",
      "style" : "standard",
      "_eventName" : "fb_like_control_impression",
      "sound_enabled" : true,
      "object_type" : "unknown",
      "_logTime" : 1505487259,
      "_ui" : "no_ui",
      "auxiliary_position" : "inline",
      "object_id" : "https:\/\/www.facebook.com\/FacebookDevelopers",
      "_implicitlyLogged" : "1"
    },
    "isImplicit" : true
  },
  {
    "event" : {
      "horizontal_alignment" : "left",
      "style" : "standard",
      "_eventName" : "fb_like_button_impression",
      "sound_enabled" : true,
      "object_type" : "unknown",
      "_logTime" : 1505487259,
      "_ui" : "no_ui",
      "auxiliary_position" : "inline",
      "object_id" : "https:\/\/www.facebook.com\/FacebookDevelopers",
      "_implicitlyLogged" : "1"
    },
    "isImplicit" : true
  }
]
Flush Result : Success

But in the screen I don’t view the button. How can I catch the event for show the button?

Thanks.

EDIT: I found the problem of Like button. It works fine!

Well, I solved 2 problems of 3.
My last problem is the method inviteFriends. Now, I haven’t an error, but It does not work.

When I call the method, the facebook app opens and I can select a friends and send invitations. When I send the invitations, FacebookListener calls onInviteFriendsResult and everything works fine. The result variable is true and the msg is empty.

But my friends does not receive the notifications. I’m testing between 2 testers users, created in the facebook panel. I don’t understand what could be the problem. @yinjimmy ?

need to check both facebook app and website.

Yes, i’m checking the app and the website, and I haven’t notifications in my test users. Perhaps if I publish the app it works… but it is rare…

can you add me as your tester ? my fb id 100003676714850.

done.
and now?

plz invite me.

you are in my testers list.