Developers Manual > Cocos2d-x > Advanced Features > Third Party SDK Integration > Plugin-X > Facebook Support for Cocos2d-x Beta > Facebook API Reference for Cocos2d-x and Cocos2d-x-lua

(!) Plugin-X is obsoleted. Please check out SDKBOX for helps with your service SDK integration.

Facebook API Reference for Cocos2d-x and Cocos2d-x-lua

cocos2d::plugin::FacebookAgent is a singleton class that encapsulates the methods of Facebook Integration for Cocos2d-x, when it was bound fo lua ,we use plugin.FacebookAgent represent it.

Core Methods

getInstance

Initialize the SDK, and return the instance of cocos2d::plugin::FacebookAgent. Required before doing anything else.

The declaration of getInstance as follows:

cpp:

1
        static FacebookAgent* getInstance()

lua:

1
       getInstance()

Example:
cpp:

1
       auto facebook = cocos2d::plugin::FacebookAgent::getInstance();

lua:

1
       local facebook = plugin.FacebookAgent:getInstance()

destroyInstance

Destroy the instance of cocos2d::plugin::FacebookAgent|

The declaration of destroyInstance as follows:

cpp:

1
       static void destroyInstance()

lua:

1
       destroyInstance()

Example:

cpp:

1
2
       auto facebook = cocos2d::plugin::FacebookAgent::getInstance();
       cocos2d::plugin::FacebookAgent::destroyInstance()

lua:

1
2
       local facebook = plugin.FacebookAgent:getInstance()
       plugin.FacebookAgent:destroyInstance()

api

Makes a call to the Facebook Graph API to get data, or take action on a user's behalf. This will almost always be used once a user is logged in, and an access token has been granted; the permissions encoded by the access token determine which Graph API calls will be available.

The declaration of api as follows:

cpp:

1
      void api(std::string &path, int method, FBInfo &params, FBCallback cb)

lua:

1
     api(path, method, params, cb)

The detail of parameters of api is as follow:

Name Type Required Description
path String Yes The Graph API endpoint to call
method cocos2d::plugin::FacebookAgent::HttpMethod Yes The
params Object No The key/value pairs to be passed to the endpoint as arguments. For details of arguments for each endpoint, please refer to Graph API Reference
cb Function No Callback function containing a result code and a JSON response.

Example:

cpp:

1
2
3
4
5
       std::string path = "/me/permissions";
       FacebookAgent::FBInfo params;
       FacebookAgent::getInstance()->api(path, FacebookAgent::HttpMethod::Get, params, [=](int ret, std::string& msg){
             //do something
       });

lua:

1
2
3
4
5
6
      local path = "/me/permissions"
      if plugin.FacebookAgent:getInstance():isLoggedIn() then
              plugin.FacebookAgent:getInstance():api(path,  plugin.FacebookAgent.HttpMethod.GET, {}, function(ret, msg)
                    -- do something
            end)
      end

dialog

This method is used to trigger different forms of Facebook created UI dialogs. These dialogs include:

  • The Share Dialog for one-to-many sharing on Facebook.
  • The Message Dialog for sending messages to friends.
  • The Feed Dialog, which is a web-based dialog for sharing that works on all devices, even if people don't have the Facebook for iOS app or Facebook for Android app installed, at the expense of an optimum experience for people using your apps (compared to the Share Dialog).

The declaration of dialog as follows:

cpp:

1
       void dialog(FBInfo &info, FBCallback cb)

lua:

1
       dialog(info, cb)

The detail of parameters of api is as follow:

Name Type Required Description
info object Yes The object to contain the details of the sharing.
cb function No Callback function containing a result code and a JSON response.

The properties of info object:

Name Type Required Description
dialog string Yes This property determines the share dialog type that you want to trigger.
other properties various Yes Additional properties are based on the share dialog type you use. See details below.

There are three dialog types,the details as follow:

-Share Dialog:
Allow people to share a link, a structured Open Graph story or a photo from your app.

On iOS or Android, if the person has installed the native Facebook for iOS app or the native Facebook for Android app in the device, this method does an app switch to the native Facebook for iOS app or the native Facebook for Android app installed in the device, from which the person shares the content. Then it returns to your app once people have shared. Please note that your app does not have to be using Facebook Login for people to be able to share via the Share Dialog. Otherwise, if the person does not have the native Facebook for iOS app or the native Facebook for Android app installed in the device, the method automatically falls back to the Feed Dialog (a web dialog that doesn't need the native Facebook for iOS app or the native Facebook for Android app installed). Please visit Sharing in iOS and Sharing in Android for more details.

The types of share dialog as follow:

Value Dialog type
shareLink Share a link
sharePhoto Share a photo
shareOpenGraph Share a structured Open Graph story

Additional properties of info object based on each Share Dialog type:
1.shareLink

Name Type Description Default
to string The Facebook user ID or username of the user on whose timeline the story should be posted The current user
link string The URL to which this post should link The base URL of the posting application, as configured in the Developer App
name string The name of the story, shown at the top and rendered as a hyperlink with href set to link The app name, as configured in the Developer App
caption string A short description, rendered below linkName in the story The app base URL
description string A longer description, rendered as the main body of the story None
picture string The URL of a picture, in PNG of JPEG format, to display beside the story; see the Feed Dialog documentation for details None
media_source string The URL of audio or video content to display beside the story; see Feed Gaming documentation for details None
action_name string The text of the action link; see actionLink, below None
action_link string A link rendered at the bottom of the story which can optionally have a different target than the main story link; see documentation None
reference string A name for the category of feed post, used in Facebook Insights to help you measure the performance of different types of post None
properties object Links which will be rendered at the bottom of the Feed story. Keys must be strings. Values can be either strings (in which case the story will have the key as text and the value as the link URL), or length-2 string arrays where the 0th value is the text and the 1st value the URL to link to. None

2.sharePhoto

Please note that you can only share one photo with Share Dialog on iOS and Android.

Name Type Description
photo string The path of the photo

3.shareOpenGraph

Please note that you can only share a structured Open Graph story with Share Dialog on iOS and Android.

// TODO: this is not done. Need improvement.

Name Type Description
object_type string
title string
image string
url string
description string
preview_property_name string
action_type string

Examples:

  1. share a link

cpp:

1
2
3
4
5
6
7
8
9
       FacebookAgent::FBInfo params;
       params.insert(std::make_pair("dialog", "share_link"));
       params.insert(std::make_pair("link", "http://www.cocos2d-x.org"));
       if (FacebookAgent::getInstance()->canPresentDialogWithParams(params))
       {
                FacebookAgent::getInstance()->dialog(params, [=](int ret ,std::string& msg){
                        CCLOG("%s", msg.c_str());
                 });
        }

lua:

1
2
3
4
5
6
7
8
9
10
        local params = {
            dialog = "share_link",
            link   = "http://www.cocos2d-x.org",
        }

        if plugin.FacebookAgent:getInstance():canPresentDialogWithParams(params) then
            plugin.FacebookAgent:getInstance():dialog(params, function(ret, msg)
                print(msg)
            end)
       end
  1. share a photo:

cpp

1
2
3
4
5
6
7
8
9
10
     FacebookAgent::FBInfo params;
     params.insert(std::make_pair("dialog", "share_photo"));
     params.insert(std::make_pair("photo", imgPath));

     if (FacebookAgent::getInstance()->canPresentDialogWithParams(params))
     {
            FacebookAgent::getInstance()->dialog(params, [=](int ret, std::string& msg){
                        CCLOG("%s", msg.c_str());
            });
      }

lua

1
2
3
4
5
6
7
8
9
10
    local params = {
            dialog = "share_photo",
            photo  = imgPath,
     }

     if plugin.FacebookAgent:getInstance():canPresentDialogWithParams(params) then
              plugin.FacebookAgent:getInstance():dialog(params, function(ret, msg)
                     print(msg)
              end)
     end
  1. share an open graph story

cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
            FacebookAgent::FBInfo params;
            params.insert(std::make_pair("dialog", "share_open_graph"));
            params.insert(std::make_pair("action_type", "cocostestmyfc:share"));
            params.insert(std::make_pair("preview_property_name", "cocos_document"));
            params.insert(std::make_pair("title", "Cocos2d-x Game Engine"));
            params.insert(std::make_pair("image", "http://files.cocos2d-x.org/images/orgsite/logo.png"));
            params.insert(std::make_pair("url", "http://cocos2d-x.org/docs/catalog/en"));
            params.insert(std::make_pair("description", "cocos document"));

            if (FacebookAgent::getInstance()->canPresentDialogWithParams(params))
            {
                FacebookAgent::getInstance()->dialog(params, [=](int ret ,std::string& msg){
                    CCLOG("%s", msg.c_str());
                });
            }

lua:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
            local params = {
            dialog = "share_open_graph",
            action_type = "cocostestmyfc:share",
            preview_property_name =  "cocos_document",
            title = "Cocos2dx-lua Game Engine",
            image =  "http://files.cocos2d-x.org/images/orgsite/logo.png",
            url = "http://cocos2d-x.org/docs/catalog/en",
            description = "cocos document",
            }

            if plugin.FacebookAgent:getInstance():canPresentDialogWithParams(params) then
                plugin.FacebookAgent:getInstance():dialog(params, function(ret, msg)
                    print(msg)
                end)
            else
                print("Can't open dialog for share_open_graph")
            end

-Message Dialog:
Allow people to Message a link, a structured Open Graph story or a photo from your app to their friends.

On iOS or Android, it triggers the Message Dialog. The Message Dialog requires that the user has the Facebook Messenger app installed on their device. Please refer to Sharing in iOS and Sharing in Android for more details. Note that your app does not have to be using Facebook Login for people to be able to share via the Message Dialog.

The types of message dialog as follows:

Value Dialog type
messageLink Message a link to friends
messagePhoto Message a photo to friends
messageOpenGraph Message an Open Graph story to friends

Additional properties of info object for each message dialog type as follows:

1.messageLink

Name Type Description
link string the url we want to share.
name string a title.
caption string a subtitle.
description string a snippet of text describing the content of the link.
picture string the url of a thumbnail to associate with the post.

2.messagePhoto

Please note that you can only message one photo with Message Dialog on iOS and Android.

Name Type Description
photo string The path of the photo

3.messageOpenGraph

Please note that you can only share a structured Open Graph story with Message Dialog on iOS and Android.

// TODO: this is not done. Need improvement.

Name Type Description
object_type string
title string
image string
url string
description string
preview_property_name string
action_type string

Example:

1.Message a link

cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
            FacebookAgent::FBInfo params;
            params.insert(std::make_pair("dialog", "message_link"));
            params.insert(std::make_pair("description", "Cocos2d-x is a great game engine"));
            params.insert(std::make_pair("title", "Cocos2d-x"));
            params.insert(std::make_pair("link", "http://www.cocos2d-x.org"));
            params.insert(std::make_pair("imageUrl", "http://files.cocos2d-x.org/images/orgsite/logo.png"));

            if (FacebookAgent::getInstance()->canPresentDialogWithParams(params))
            {
                FacebookAgent::getInstance()->dialog(params, [=](int ret, std::string& msg){
                    CCLOG("%s", msg.c_str());
                });
            }

lua:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
           local params = {
                dialog = "message_link",
                description =  "Cocos2dx-lua is a great game engine",
                title = "Cocos2dx-lua",
                link = "http://www.cocos2d-x.org",
                imageUrl = "http://files.cocos2d-x.org/images/orgsite/logo.png",
            }

            if plugin.FacebookAgent:getInstance():canPresentDialogWithParams(params) then
                plugin.FacebookAgent:getInstance():dialog(params, function(ret, msg )
                    print(msg)
                end)
            else
                print("Can't open dialog for message_link")
            end

2.Message a photo

cpp:

1
2
3
4
5
6
7
8
9
10
            FacebookAgent::FBInfo params;
            params.insert(std::make_pair("dialog", "message_photo"));
            params.insert(std::make_pair("photo", imgPath));

            if (FacebookAgent::getInstance()->canPresentDialogWithParams(params))
            {
                 FacebookAgent::getInstance()->dialog(params, [=](int ret, std::string& msg){
                        CCLOG("%s", msg.c_str());
                  });
            }

lua:

1
2
3
4
5
6
7
8
9
10
11
           local params = {
                 dialog = "message_photo",
                 photo  = imgPath,
           }
          if plugin.FacebookAgent:getInstance():canPresentDialogWithParams(params) then
                plugin.FacebookAgent:getInstance():dialog(params, function(ret, msg )
                    print(msg)
                end)
          else
                print("Can't open dialog for message_photo")
          end

3.Message an open graph story

cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
         FacebookAgent::FBInfo params;
         params.insert(std::make_pair("dialog", "message_open_graph"));
         params.insert(std::make_pair("action_type", "cocostestmyfc:share"));
         params.insert(std::make_pair("preview_property_name", "cocos_document"));
         params.insert(std::make_pair("title", "Cocos2d-x Game Engine"));
         params.insert(std::make_pair("image", "http://files.cocos2d-x.org/images/orgsite/logo.png"));
         params.insert(std::make_pair("url", "http://cocos2d-x.org/docs/catalog/en"));
         params.insert(std::make_pair("description", "cocos document"));
         if (FacebookAgent::getInstance()->canPresentDialogWithParams(params))
         {
             FacebookAgent::getInstance()->dialog(params, [=](int ret, std::string& msg){
                    CCLOG("%s", msg.c_str());
              });
          }

lua:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
         local params = {
                dialog = "message_open_graph",
                action_type = "cocostestmyfc:share",
                preview_property_name = "cocos_document",
                title =  "Cocos2dx-lua Game Engine",
                image = "http://files.cocos2d-x.org/images/orgsite/logo.png",
                url =  "http://cocos2d-x.org/docs/catalog/en",
                description =  "cocos document",
         }

         if plugin.FacebookAgent:getInstance():canPresentDialogWithParams(params) then
                plugin.FacebookAgent:getInstance():dialog(params, function(ret, msg )
                    print(msg)
                end)
         else
                print("Can't open dialog for message_open_graph")
         end
  • Feed Dialog The Feed dialog publishes posts to the Facebook newsfeed. The Feed dialog is a web-based dialog that works on all devices, even if people don't have the Facebook for iOS app or Facebook for Android app installed, at the expense of an optimum experience for people using your apps (compared to the Share Dialog).

On iOS or Android, since the Feed dialog opens a web page for sharing, it must start by asking people for their Facebook credentials in order to verify their identity, which disrupts the sharing flow. People are also asked to re-enter their credentials over time as their password changes. The Feed dialog does not support Open Graph and supports only the basic attachment model which includes a link, title/description text and an image. So we recommend that you use the Share Dialog and you implement the Feed Dialog as fallback for the cases where the Facebook for iOS app or the Facebook for Android app is not present or the Share Dialog is not supported (for example, due to an old version of the Facebook for iOS app or the Facebook for Android app being installed). As mentioned, the Feed dialog does not support publishing Open Graph stories, so if you're using the Feed Dialog as fallback for the Share Dialog when publishing an Open Graph story you will need to adapt the contents to post a link (optionally with an image and text) instead.

The properties of info object as follow:

Name Type Description Default
dialog string You should use feedDialog None
to string The Facebook user ID or username of the user on whose timeline the story should be posted The current user
link string The URL to which this post should link The base URL of the posting application, as configured in the Developer App
name string The name of the story, shown at the top and rendered as a hyperlink with href set to link The app name, as configured in the Developer App
caption string A short description, rendered below linkName in the story The app base URL
description string A longer description, rendered as the main body of the story None
picture string The URL of a picture, in PNG of JPEG format, to display beside the story; see the Feed Dialog documentation for details None

Example:

cpp:

1
2
3
4
5
6
7
        FacebookAgent::FBInfo params;
        params.insert(std::make_pair("dialog", "feed_dialog"));
        params.insert(std::make_pair("link", "http://www.cocos2d-x.org"));

        FacebookAgent::getInstance()->dialog(params, [=](int ret ,std::string& msg){
                        CCLOG("%s", msg.c_str());
        });

lua:

1
2
3
4
5
6
7
8
        local params = {
            dialog = "feed_dialog",
            link   = "http://www.cocos2d-x.org",
        }

        plugin.FacebookAgent:getInstance():dialog(params, function(ret, msg)
                print(msg)
        end)

canPresentDialogWithParams

This method is to determine if the device is capable of presenting the particular dialog, as documented in dialog doc. These dialogs this method can check include:

  • The Share Dialog
  • The Message Dialog

If it is capable, it returns true, otherwise it returns false.

The declaration of canPresentDialogWithParams as follows:

cpp:

1
       bool canPresentDialogWithParams(FBInfo &info)

lua:

1
      canPresentDialogWithParams(info)

The parameters as follow:

Name Type Required Description
info Object Yes The dialog info as the one which will be passed in the dialog API.

The dialog types in the info as follows:

Value Dialog type
shareLink Share Dialog for sharing a link
sharePhoto Share Dialog for sharing a photo
shareOpenGraph Share Dialog for sharing a structured Open Graph story
messageLink Message Dialog for messaging a link to friends
messagePhoto Message Dialog for messaging a photo to friends
messageOpenGraph Message Dialog for messaging an Open Graph story to friends

Example:

cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
            FacebookAgent::FBInfo params;
            params.insert(std::make_pair("dialog", "share_link"));
            params.insert(std::make_pair("link", "http://www.cocos2d-x.org"));
            if (FacebookAgent::getInstance()->canPresentDialogWithParams(params))
            {
                FacebookAgent::getInstance()->dialog(params, [=](int ret, std::string& msg){
                    CCLOG("%s", msg.c_str());
                });
            }
            else
            {
                    params.insert(std::make_pair("dialog", "feed_dialog"));
                    FacebookAgent::getInstance()->dialog(params, [=](int ret ,std::string& msg){
                        CCLOG("%s", msg.c_str());
                    });
             }

lua:

1
2
3
4
5
6
7
8
9
10
          local params = {
             dialog = "share_link",
             link   = "http://www.cocos2d-x.org",
          }

          if plugin.FacebookAgent:getInstance():canPresentDialogWithParams(params) then
             plugin.FacebookAgent:getInstance():dialog(params, function(ret, msg)
                print(msg)
             end)
         end

appRequest

This method triggers Requests Dialog, which is invoked in-game via the Facebook SDK on iOS, Android and Canvas. Requests can contain a user-facing message as plain text, which is passed as a parameter when invoking the dialog, or they can contain specific information including in-game items and explicit calls to action. Requests give players a mechanism for inviting their friends to play a game. Requests are sent by a player to one or more specific friends, and always carry a call-to-action that the sender wants the recipient to complete. Recipients can choose to accept the request, or they can choose to ignore or decline it.

For more details, please refer to doc Requests.
NOTE: Request Dialog in Cocos SDK does not support Frictionless Requests for now.

The declaration of appRequest as follows:

cpp:

1
       void appRequest(FBInfo &info, FBCallback cb)

lua:

1
      appRequest(info, cb)

The detail of parameters as follows:

Name Type Required Description
info Object Yes The object to contain the details of the request.
cb Function No Callback function containing a result code and a JSON response.

The info supports all the parameters listed in Dialog Parameters Section in the doc.

Example:

cpp:

1
2
3
4
5
6
7
         FacebookAgent::FBInfo params;
         params.insert(std::make_pair("message", "Cocos2d-x is a great game engine"));
         params.insert(std::make_pair("title", "Cocos2d-x title"));

         FacebookAgent::getInstance()->appRequest(params, [=](int ret, std::string& msg){
                    CCLOG("%s", msg.c_str());
         });

lua:

1
2
3
4
5
6
7
8
        local params = {
            message = "Cocos2dx-lua is a great game engine",
            title   = "Cocos2dx-lua title",
        }

        plugin.FacebookAgent:getInstance():appRequest(params, function(ret, msg)
            print(msg)
        end)

Auth and Session Methods

login

Prompts the user to authorize your application using the Login Dialog appropriate to the platform. If the user is already logged in and has authorized your application, checks whether all permissions in the permissions parameter have been granted, and if not, prompts the user for any that are newly requested. Usually, you'll call it once to ask the user for authentication, then again to request additional permissions as required.

The declaration of login as follows:

cpp:

1
2
     void login(FBCallback cb) 
     void login(std::string& permissions, FBCallback cb)

lua:

1
2
     login(cb) 
     login(permissions, cb)

The detail of parameters as follows:

Name Type Required Description
permissions Array of strings No A list of Facebook permissions to request from the user.
cb Function No Callback function containing a result code and a JSON response.

Example:

cpp:

1
2
3
4
5
6
7
8
9
10
      //for login(FBCallback cb)
      FacebookAgent::getInstance()->login([=](int ret, std::string& msg){
                    CCLOG(StringUtils::format("type is %d, msg is %s", ret, msg.c_str()));
                });

     //for login(std::string& permissions, FBCallback cb)
     std::string permissions = "create_event,create_note,manage_pages,publish_actions,user_about_me";
     FacebookAgent::getInstance()->login(permissions, [=](int ret, std::string& msg){
                CCLOG(msg.c_str());
     }

lua:

1
2
3
4
5
6
7
8
9
10
      --for login(cb)
     plugin.FacebookAgent:getInstance():login(function(ret, msg)
              self.infoLabel:setString(string.format("type is %d, msg is %s", ret, msg))
     end )

     --for login(permissions, cb)
     local permissions = "create_event,create_note,manage_pages,publish_actions,user_about_me"
         plugin.FacebookAgent:getInstance():login(permissions, function(ret, msg)
                self.infoLabel:setString(msg)
         end)

logout

Log the user out of both your site and Facebook. Will also invalidate any access token that you have for the user that was issued before the logout.

The declaration of logout as follows:

cpp:

1
     void logout()

lua:

1
     logout()

Example:

cpp:

1
      FacebookAgent::getInstance()->logout();

lua:

1
    plugin.FacebookAgent:getInstance():logout()

isLoggedIn

Check the user's authorization status. false if the user has not logged into Facebook, or hasn't authorized your app; true otherwise. Most often, this will be in the logic that determines whether to show a login control.

The declaration of isLoggedIn as follows:

cpp:

1
       bool isLoggedIn()

lua:

1
       isLoggedIn()

Example:

cpp:

1
2
3
4
5
6
7
8
       if (FacebookAgent::getInstance()->isLoggedIn())
       {
              //do something
       }
       else
       {
              //do something
       }

lua:

1
2
3
4
5
       if  plugin.FacebookAgent:getInstance():isLoggedIn() then
              //do something
       else
              //do something
       end

getUserId

The user's Facebook user ID, when a user is logged in and has authorized your app, or an empty string if not.

The declaration of getUserId as follows:

cpp:

1
      std::string getUserID()

lua:

1
      getUserID()

Example:

cpp:

1
    std::string userID = FacebookAgent::getInstance()->getUserID();

lua:

1
    local userID = plugin.FacebookAgent::getInstance():getUserID()

getAccessToken

Returns the access token granted to your app when the user most recently authorized it; otherwise, an empty string.

The declaration of getAccessToken as follows:

cpp:

1
     std::string getAccessToken()

lua:

1
     getAccessToken()

Example:

cpp:

1
    std::string accessToken = FacebookAgent::getInstance()->getAccessToken();

lua:

1
    local accessToken = plugin.FacebookAgent:getInstance():getAccessToken()

Auxiliary Methods

activateApp

Report the launch of the app, for integration with Facebook app ads. More details at App Events.

The declaration of activateApp as follows:

cpp:

1
     void activateApp()

lua:

1
    activateApp()

Example:

cpp:

1
    FacebookAgent::getInstance()->activateApp();

lua:

1
    plugin.FacebookAgent:getInstance():activateApp()

logEvent

Publishes an App Event. More details at App Events.

The declaration of logEvent as follows:

cpp:

1
2
3
4
    void logEvent(std::string& eventName);
    void logEvent(std::string& eventName, float valueToSum);
    void logEvent(std::string& eventName, FBInfo& parameters);
    void logEvent(std::string& eventName, float valueToSum, FBInfo& parameters);

lua:

1
2
3
4
    logEvent(eventName);
    logEvent(eventName, valueToSum);
    logEvent(eventName, parameters);
    logEvent(eventName, valueToSum, parameters);

the detail of parameters as follows:

Name Type Required Description
eventName string Yes The name of the event to log
valueToSum float No An number representing some value to be summed when reported
parameters Dictionary No Any parameters needed to describe the event

Different eventName corresponding to different meanings:

EventName Meaning
fb_mobile_level_achieved The user has achieved a level in the app.
fb_mobile_activate_app An app is being activated.
fb_mobile_add_payment_info The user has entered their payment info.
fb_mobile_add_to_cart The user has added an item to their cart. The valueToSum passed to logEvent should be the item's price.
fb_mobile_add_to_wishlist The user has added an item to their wishlist. The valueToSum passed to logEvent should be the item's price.
fb_mobile_complete_registration A user has completed registration with the app.
fb_mobile_tutorial_completion The user has completed a tutorial in the app.
fb_mobile_initiated_checkout The user has entered the checkout process. The valueToSum passed to logEvent should be the total price in the cart.
fb_mobile_purchase The user has completed a purchase.
fb_mobile_rate The user has rated an item in the app. The valueToSum passed to logEvent should be the numeric rating.
fb_mobile_search A user has performed a search within the app.
fb_mobile_spent_credits The user has spent app credits. The valueToSum passed to logEvent should be the number of credits spent.
fb_mobile_achievement_unlocked The user has unlocked an achievement in the app.
fb_mobile_content_view A user has viewed a form of content in the app.
fb_content_id An ID for the specific piece of content being logged about. Could be an EAN, article identifier, etc., depending on the nature of the app.
fb_content_type A generic content type/family for the logged event, e.g. "music", "photo", "video". Options to use will vary based upon what the app is all about.
fb_currency ISO-4217 3-letter code for currency used (e.g. "USD", "EUR", "GBP").
fb_description A description appropriate to the event being logged. E.g., the name of the achievement unlocked in the plugin.FacebookAgent.AppEvent.UNLOCKED_ACHIEVEMENT event.
fb_level The level achieved in a plugin.FacebookAgent.AppEvent.ACHIEVED_LEVEL event.
fb_max_rating_value The maximum rating available for the plugin.FacebookAgent.AppEvent.RATED event. E.g., "5" or "10".
fb_num_items How many items are being processed for an plugin.FacebookAgent.AppEvent.INITIATED_CHECKOUT or plugin.FacebookAgent.AppEvent.PURCHASED event.
fb_payment_info_available Whether payment info is available for the plugin.FacebookAgent.AppEvent.INITIATED_CHECKOUT event.
fb_registration_method Method user has used to register for the app, e.g., "Facebook", "email", "Twitter", etc
fb_search_string The string provided by the user for a search operation.
fb_success Whether the activity being logged about was successful or not.

Example:

cpp:

1
2
3
4
5
6
7
        std::string appEventMsg = "fb_mobile_tutorial_completion";
        float floatVal = 888.888;
        FacebookAgent::FBInfo fbInfo;
        fbInfo["fb_success"] = "1";
        FacebookAgent::getInstance()->logEvent(appEventMsg, floatVal);
        FacebookAgent::getInstance()->logEvent(appEventMsg, fbInfo);
        FacebookAgent::getInstance()->logEvent(appEventMsg, floatVal, fbInfo);

lua:

1
2
3
4
5
6
        local floatVal = 888.888
        local fbInfo = {}
        fbInfo[plugin.FacebookAgent.AppEventParam.SUCCESS] =  plugin.FacebookAgent.AppEventParamValue.VALUE_YES
        plugin.FacebookAgent:getInstance():logEvent(plugin.FacebookAgent.AppEvent.COMPLETED_TUTORIAL, floatVal)
        plugin.FacebookAgent:getInstance():logEvent(plugin.FacebookAgent.AppEvent.COMPLETED_TUTORIAL, fbInfo)
        plugin.FacebookAgent:getInstance():logEvent(plugin.FacebookAgent.AppEvent.COMPLETED_TUTORIAL, floatVal, fbInfo)

logPurchase

Logs real-money in-app purchases through App Events, which is the most common use of event logging. More details at App Events.

The declaration of logPurchase as follows:

cpp:

1
2
      void logPurchase(float mount,std::string currency);
      void logPurchase(float mount,std::string currency,FBInfo &parmeters);

lua:

1
2
      logPurchase(mount, currency);
      logPurchase(mount, currency, parmeters);

the detail of parameters as follows:

Name Type Required Description
amount float Yes The amount of currency the user spent
currency string No ISO-4217 3-letter code for currency used (e.g. "USD", "EUR", "GBP")
parameters Dictionary No Any parameters needed to describe the event

Example:

cpp:

1
2
3
         FacebookAgent::FBInfo fbInfo;
         fbInfo["fb_currency"] = "CNY";
         FacebookAgent::getInstance()->logPurchase(1.23, "CNY", fbInfo);

lua:

1
2
3
4
5
         local mount = 1.23
         local currency = "CNY"
         local fbInfo = {}
         fbInfo["fb_currency"] = "CNY"
         plugin.FacebookAgent:getInstance():logPurchase(mount, currency, fbInfo)

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.