Skip to content

Commit

Permalink
Update to 17.0.0 (#58)
Browse files Browse the repository at this point in the history
* update to 17.0.0

* add limited login APIs

* add API documentation

* add Limited login docs
  • Loading branch information
AGulev committed Apr 10, 2024
1 parent a76536c commit d4b622e
Show file tree
Hide file tree
Showing 9 changed files with 988 additions and 185 deletions.
17 changes: 16 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,21 @@ For HTML5 games, the process is a bit different. Facebook needs access to your g

The game now works through the Facebook URL provided as *Canvas Page*.

## Limited Login (iOS)

Starting with Facebook SDK 17.0 (Defold Facebook Extension 8.0.0+), new APIs has been added for the use of Limited Login.

* `facebook.login_with_tracking_preference()` - Login to Facebook and request a set of permissions. Allows developers to signal that a login is limited in terms of tracking users.
* `facebook.get_current_authentication_token()` - This function returns the currently stored authentication token after a previous successful login.
* `facebook.get_current_profile()` - After your application receives the logged-in user’s authentication token, you can use this function to read information that user has granted to your application.
* `facebook.LOGIN_TRACKING_ENABLED` - available only if in App Tracking Transparency request user enabled tracking.
* `facebook.LOGIN_TRACKING_LIMITED` - should beused if in App Tracking Transparency request user disabled tracking.

If the user has disabled tracking but you still attempt to log in using `facebook.login_with_permissions()` or its equivalent `facebook.login_with_tracking_preference()` with `facebook.LOGIN_TRACKING_ENABLED`, you will receive a Facebook Access token.

More information about the changes is available in the official Facebook documentation:
* [Changes made to Facebook Login SDK for iOS](https://developers.facebook.com/blog/post/2024/03/28/changes-made-to-fb-login-sdk/)
* [Limited Login for iOS](https://developers.facebook.com/docs/facebook-login/limited-login/ios)

## Testing the setup

Expand Down Expand Up @@ -196,7 +211,7 @@ function init(self)
end
```

Available predefined events and parameters can be seen in the [Facebook extension API reference](https://defold.github.io/extension-facebook/). These should correlate to the [Standard Events](https://developers.facebook.com/docs/analytics/send_data/events#standard) and [Parameters](https://developers.facebook.com/docs/analytics/send_data/events#parameter) from the Facebook developer documentation.
Available predefined events and parameters can be seen in the [Facebook extension API reference](https://defold.com/extension-facebook/facebook_api/). These should correlate to the [Standard Events](https://developers.facebook.com/docs/analytics/send_data/events#standard) and [Parameters](https://developers.facebook.com/docs/analytics/send_data/events#parameter) from the Facebook developer documentation.

The Facebook SDK used by Defold will also automatically generate several events, such as app install and app launch. Refer to the [Auto-logged events](https://developers.facebook.com/docs/analytics/send_data/events#autologged) in the Facebook developer documentation.

Expand Down
121 changes: 121 additions & 0 deletions facebook/api/facebook.script_api
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,77 @@
end)
```

#*****************************************************************************************************

- name: login_with_tracking_preference
type: function
desc: iOS ONLY. Login to Facebook and request a set of permissions. Allows developers to signal that a login is limited in terms of tracking users.

The user is prompted to authorize the application using the login dialog of the specific
platform. Even if the user is already logged in to Facebook this function can still be used to request additional publish permissions.

A comprehensive list of permissions can be found in the [Facebook permissions](https://developers.facebook.com/docs/facebook-login/permissions) documentation,
as well as in their [guide to best practices for login management](https://developers.facebook.com/docs/facebook-login/best-practices).
For Limited Login the list of permissions can be found in the [Permissions in Limited Login](https://developers.facebook.com/docs/facebook-login/limited-login/permissions) documentation.

parameters:
- name: login_tracking
type: number
desc: The tracking type for the login.
Can be any of

- `facebook.LOGIN_TRACKING_LIMITED`

- `facebook.LOGIN_TRACKING_ENABLED`
- name: permissions
type: table
desc: table with the requested publish permission strings.
- name: crypto_nonce
type: string
desc: Nonce that the configuration was created with. A unique nonce will be used if none is provided to the factory method.

- name: callback
type: function
desc: Callback function that is executed when the permission request dialog is closed.
parameters:
- name: self
type: object
desc: The context of the calling script

- name: data
type: table
desc: A table that contains the response

examples:
- desc: |-
Log in to Facebook with a set of publish permissions
```lua
local permissions = {"publish_actions"}
facebook.login_with_permissions(permissions, facebook.AUDIENCE_FRIENDS, function(self, data)
if (data.status == facebook.STATE_OPEN and data.error == nil) then
print("Successfully logged into Facebook")
pprint(facebook.permissions())
else
print("Failed to get permissions (" .. data.status .. ")")
pprint(data)
end
end)
```

Log in to Facebook with a set of read permissions
```lua
local permissions = {"public_profile", "email", "user_friends"}
facebook.login_with_tracking_preference(facebook.LOGIN_TRACKING_LIMITED, permissions, "customcryptononce", function(self, data)
if (data.status == facebook.STATE_OPEN and data.error == nil) then
print("Successfully logged into Facebook")
pprint(facebook.permissions())
else
print("Failed to get permissions (" .. data.status .. ")")
pprint(data)
end
end)
```

#*****************************************************************************************************

- name: logout
Expand All @@ -83,6 +154,48 @@

#*****************************************************************************************************

- name: set_default_audience
type: function
desc: iOS ONLY. The audience that should be able to see the publications. Should be called before `facebook.login_with_tracking_preference()`;
Can be any of

- `facebook.AUDIENCE_NONE`

- `facebook.AUDIENCE_ONLYME`

- `facebook.AUDIENCE_FRIENDS`

- `facebook.AUDIENCE_EVERYONE`
#*****************************************************************************************************

- name: get_current_authentication_token
type: function
desc: iOS ONLY. Get the current AuthenticationToken.

This function returns the currently stored authentication token after a previous
successful login. If it returns nil no access token exists and you need
to perform a login to get the wanted permissions.

returns:
- name: authentication_token
type: string
desc: the authentication token or nil if the user is not logged in

#*****************************************************************************************************

- name: get_current_profile
type: function
desc: iOS ONLY. Get the users [FBSDKProfile.currentProfile](https://developers.facebook.com/docs/facebook-login/limited-login/ios/).
[Reading From Profile Helper Class](https://developers.facebook.com/docs/facebook-login/limited-login/permissions/profile-helper)

returns:
- name: current_profile
type: table
desc: After your application receives the logged-in user’s authentication token, you can use
this function to read information that user has granted to your application.

#****************************************************************************************************

- name: init
type: function
desc: Initialize Facebook SDK (if facebook.autoinit is 0 in game.project)
Expand Down Expand Up @@ -648,3 +761,11 @@
- name: AUDIENCE_EVERYONE
type: number
desc: Publish permission to reach everyone

- name: LOGIN_TRACKING_LIMITED
type: number
desc: Login tracking Limited

- name: LOGIN_TRACKING_ENABLED
type: number
desc: Login tracking enabled
10 changes: 5 additions & 5 deletions facebook/manifests/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ repositories {

dependencies {
// https://developers.facebook.com/docs/android/getting-started/
implementation 'com.facebook.android:facebook-core:14.1.1'
implementation 'com.facebook.android:facebook-login:14.1.1'
implementation 'com.facebook.android:facebook-share:14.1.1'
implementation 'com.facebook.android:facebook-messenger:14.1.1'
implementation 'com.facebook.android:facebook-applinks:14.1.1'
implementation 'com.facebook.android:facebook-core:17.0.0'
implementation 'com.facebook.android:facebook-login:17.0.0'
implementation 'com.facebook.android:facebook-share:17.0.0'
implementation 'com.facebook.android:facebook-messenger:17.0.0'
implementation 'com.facebook.android:facebook-applinks:17.0.0'
}
10 changes: 5 additions & 5 deletions facebook/manifests/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
platform :ios, '11.0'
pod 'FBSDKCoreKit', '14.1.0'
pod 'FBSDKLoginKit', '14.1.0'
pod 'FBSDKShareKit', '14.1.0'
pod 'FBSDKGamingServicesKit', '14.1.0'
platform :ios, '12.0'
pod 'FBSDKCoreKit', '17.0.0'
pod 'FBSDKLoginKit', '17.0.0'
pod 'FBSDKShareKit', '17.0.0'
pod 'FBSDKGamingServicesKit', '17.0.0'
86 changes: 86 additions & 0 deletions facebook/src/facebook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,84 @@ static int Facebook_DisableAdvertiserTracking(lua_State* L)
#endif
}

static int Facebook_SetDefaultAudience(lua_State* L)
{
#if defined(DM_PLATFORM_IOS)
CHECK_FACEBOOK_INIT(L);
DM_LUA_STACK_CHECK(L, 0);
int audience = luaL_checkinteger(L, 1);
Platform_FacebookSetDefaultAudience(audience);
return 0;
#else
dmLogWarning("`set_default_audience` is iOS only function.");
return 0;
#endif
}

static int Facebook_LoginWithTrackingPreference(lua_State* L)
{
#if defined(DM_PLATFORM_IOS)
CHECK_FACEBOOK_INIT(L);
DM_LUA_STACK_CHECK(L, 0);

int login_tracking = luaL_checkinteger(L, 1);
luaL_checktype(L, 2, LUA_TTABLE);
const char* crypto_nonce = luaL_checkstring(L, 3);
dmScript::LuaCallbackInfo* callback = dmScript::CreateCallback(L, 4);

char* permissions[128];
int permission_count = luaTableToCArray(L, 2, permissions, sizeof(permissions) / sizeof(permissions[0]));
if (permission_count == -1)
{
return luaL_error(L, "Facebook permissions must be strings");
}

Platform_FacebookLoginWithTrackingPreference((dmFacebook::LoginTracking)login_tracking, (const char**) permissions, permission_count, crypto_nonce, callback);

for (int i = 0; i < permission_count; ++i)
{
free(permissions[i]);
}
return 0;
#else
dmLogWarning("`login_with_tracking_preference` is iOS only function.");
return 0;
#endif
}

static int Facebook_GetCurrentAuthenticationToken(lua_State* L)
{
#if defined(DM_PLATFORM_IOS)
CHECK_FACEBOOK_INIT(L);
DM_LUA_STACK_CHECK(L, 1);
const char* token = Platform_FacebookGetCurrentAuthenticationToken();
if (token == 0x0)
{
lua_pushnil(L);
}
else
{
lua_pushstring(L, token);
}
return 1;
#else
dmLogWarning("`get_current_authentication_token` is iOS only function.");
return 0;
#endif
}

static int Facebook_GetCurrentProfile(lua_State* L)
{
#if defined(DM_PLATFORM_IOS)
CHECK_FACEBOOK_INIT(L);
DM_LUA_STACK_CHECK(L, 1);
return Platform_FacebookGetCurrentProfile(L);
#else
dmLogWarning("`get_current_profile` is iOS only function.");
return 0;
#endif
}

static const luaL_reg Facebook_methods[] =
{
{"init", Facebook_Init},
Expand All @@ -157,6 +235,11 @@ static const luaL_reg Facebook_methods[] =
{"deferred_deep_link", Facebook_FetchDeferredAppLinkData},
{"enable_advertiser_tracking", Facebook_EnableAdvertiserTracking},
{"disable_advertiser_tracking", Facebook_DisableAdvertiserTracking},
// iOS only function. FB SDK 17.0:
{"set_default_audience", Facebook_SetDefaultAudience},
{"login_with_tracking_preference", Facebook_LoginWithTrackingPreference},
{"get_current_authentication_token", Facebook_GetCurrentAuthenticationToken},
{"get_current_profile", Facebook_GetCurrentProfile},
{0, 0}
};

Expand Down Expand Up @@ -191,6 +274,9 @@ static void LuaInit(lua_State* L)
SETCONSTANT(AUDIENCE_FRIENDS, dmFacebook::AUDIENCE_FRIENDS);
SETCONSTANT(AUDIENCE_EVERYONE, dmFacebook::AUDIENCE_EVERYONE);

SETCONSTANT(LOGIN_TRACKING_LIMITED, dmFacebook::LOGIN_TRACKING_LIMITED);
SETCONSTANT(LOGIN_TRACKING_ENABLED, dmFacebook::LOGIN_TRACKING_ENABLED);

#undef SETCONSTANT

#if defined(DM_PLATFORM_HTML5)
Expand Down

0 comments on commit d4b622e

Please sign in to comment.