Skip to content
This repository has been archived by the owner on May 17, 2022. It is now read-only.
/ facebook-ANE Public archive

This air native extension is your best solution to integrate Facebook SDK into your AdobeAir apps

Notifications You must be signed in to change notification settings

myflashlab/facebook-ANE

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 

Repository files navigation

Facebook SDK ANE (Android + iOS)

Use this AIR Native Extension to implement the latest official Facebook SDK into your AIR applications.

Main features:

  • Login/logout
  • ask users for permissions
  • decide on your app logic based on granted permissions
  • Share URL links directly from your app
  • send Game Requests to friends
  • Support App Events for use in Facebook analytics
  • full access to Facebook Graph API... the sky is the limit!
  • works on Android and iOS with an identical AS3 library

find the latest asdoc for this ANE here.

AIR Usage

import com.myflashlab.air.extensions.fb.*;

Facebook.init("000000000000000");

// Add these listeners right after initializing the ANE but don't call any other method before FacebookEvents.INIT happens
Facebook.listener.addEventListener(FacebookEvents.INIT, onAneInit);
Facebook.listener.addEventListener(FacebookEvents.INVOKE, onAneInvoke);

// You can receive the hashKey for your Android certificate like below.
if (OverrideAir.os == OverrideAir.ANDROID) trace("hash key = ", Facebook.hashKey);

function onAneInvoke(e:FacebookEvents):void
{
	trace("onAneInvoke: " + decodeURIComponent(e.deeplink));
}

function onAneInit(e:FacebookEvents):void
{
	trace("onAneInit");
	
	// check if user is already logged in or not
	_accessToken = Facebook.auth.currentAccessToken;
	
	/*
		IMPORTANT: in practice you should let users click on a login button 
		not logging them automatically.
	*/
	if(!_accessToken) toLogin();
}

function toLogin():void
{
	/*
		It is recommended to login users with minimal permissions. Later, whe your app 
		needs more permissions, you can call "Facebook.auth.login" again with more permissions.
		
		To ask for publish permissions, set the first parameter to "true".
	*/

	var permissions:Array = [Permissions.public_profile, Permissions.user_friends, Permissions.email];
	Facebook.auth.login(false, permissions, loginCallback);
	
	function loginCallback($isCanceled:Boolean, $error:Error, $accessToken:AccessToken, $recentlyDeclined:Array, $recentlyGranted:Array):void
	{
		if($error)
		{
			trace("login error: " + $error.message);
		}
		else
		{
			if($isCanceled)
			{
				trace("login canceled by user");
			}
			else
			{
				trace("$recentlyDeclined: " + $recentlyDeclined);
				trace("$recentlyGranted: " + $recentlyGranted);
				
				_accessToken = $accessToken;
				
				trace("token: " + _accessToken.token);
				trace("userId: " + _accessToken.userId);
				trace("declinedPermissions: " + _accessToken.declinedPermissions);
				trace("grantedPermissions: " + _accessToken.grantedPermissions);
				trace("expiredPermissions: " + _accessToken.expiredPermissions);
				trace("expiration: " + new Date(_accessToken.expiration).toLocaleDateString());
				trace("lastRefresh: " + new Date(_accessToken.lastRefresh).toLocaleDateString());
				trace("dataAccessExpirationDate: " + new Date(_accessToken.dataAccessExpirationDate).toLocaleDateString());
			}
		}
	}
}

AIR .xml manifest

  <android>
    <manifestAdditions>
		<![CDATA[<manifest android:installLocation="auto">
		<uses-permission android:name="android.permission.WAKE_LOCK" />
		<uses-permission android:name="android.permission.INTERNET" />
		
		<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="28"/>
		
		<application 
			android:hardwareAccelerated="true" 
			android:allowBackup="true"
			android:name="android.support.multidex.MultiDexApplication">

			<activity android:hardwareAccelerated="false">
				<intent-filter>
					<action android:name="android.intent.action.MAIN" />
					<category android:name="android.intent.category.LAUNCHER" />
				</intent-filter>
				<intent-filter>
					<action android:name="android.intent.action.VIEW" />
					<category android:name="android.intent.category.BROWSABLE" />
					<category android:name="android.intent.category.DEFAULT" />
					
					<!-- Your application scheme. read here for more information: http://www.myflashlabs.com/open-adobe-air-app-browser-pass-parameters/ -->
					<data android:scheme="[PACKAGE_NAME]" />
				</intent-filter>
			</activity>
			
			
			
			<!-- 
				This is required by the Facebook ANE. replace the zeros with your actual Facebook App ID
				While doing that, notice the empty space after the "\ ". This is required because the ANE 
				must see the value as an String.
			-->
			<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="\ 000000000000000"/>
			
			<!-- This is required by the Facebook ANE for logging in -->
			<activity 
				android:name="com.facebook.FacebookActivity" 
				android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
				android:theme="@android:style/Theme.Translucent.NoTitleBar" 
				android:label="My App Name" />
			
			<activity android:name="com.facebook.CustomTabMainActivity" />
			<activity android:name="com.facebook.CustomTabActivity" android:exported="true">
				<intent-filter>
					<action android:name="android.intent.action.VIEW" />
					<category android:name="android.intent.category.DEFAULT" />
					<category android:name="android.intent.category.BROWSABLE" />
					<data android:scheme="fb000000000000000" />
				</intent-filter>
			</activity>
			
			<provider android:authorities="com.facebook.app.FacebookContentProvider000000000000000" android:name="com.facebook.FacebookContentProvider" android:exported="true"/>

			<receiver
				android:name="com.facebook.CurrentAccessTokenExpirationBroadcastReceiver" android:exported="false">
				<intent-filter>
					<action android:name="com.facebook.sdk.ACTION_CURRENT_ACCESS_TOKEN_CHANGED" />
				</intent-filter>
			</receiver>

			<receiver
                android:name="com.facebook.CampaignTrackingReceiver"
                android:exported="true"
                android:permission="android.permission.INSTALL_PACKAGES">
                <intent-filter>
                    <action android:name="com.android.vending.INSTALL_REFERRER"/>
                </intent-filter>
            </receiver>

		</application>
		
</manifest>]]></manifestAdditions>
  </android>
  <iPhone>

    <InfoAdditions>
		<![CDATA[<key>MinimumOSVersion</key>
		<string>10.0</string>
		
		<key>UIStatusBarStyle</key>
		<string>UIStatusBarStyleBlackOpaque</string>
		
		<key>UIRequiresPersistentWiFi</key>
		<string>NO</string>
		
		<key>FacebookAppID</key>
		<string>000000000000000</string>
		
		<key>FacebookDisplayName</key>
		<string>Air Native Extension</string>
		
		<key>CFBundleURLTypes</key>
		<array> 
			<dict>
				<key>CFBundleURLSchemes</key>
				<array>
					<string>fb000000000000000</string>
					
					<!-- Your application scheme. read here for more information: http://www.myflashlabs.com/open-adobe-air-app-browser-pass-parameters/ -->
					<string>[PACKAGE_NAME]</string>
				</array>
			</dict>
		</array>

		<key>LSApplicationQueriesSchemes</key>
		<array>
			<string>fbapi</string>
			<string>fb-messenger-api</string>
			<string>fb-messenger-share-api</string>
			<string>fb-messenger</string>
			<string>fbauth2</string>
			<string>fbshareextension</string>
		</array>
			
		<key>NSPhotoLibraryUsageDescription</key>
		<string>My description about why I need this feature in my app</string>
		
		<key>UIDeviceFamily</key>
		<array>
			<!-- iPhone support -->
			<string>1</string>
			<!-- iPad support -->
			<string>2</string>
		</array>]]></InfoAdditions>
		
    <requestedDisplayResolution>high</requestedDisplayResolution>
  </iPhone>
  
  
  
  <extensions>
  
	<extensionID>com.myflashlab.air.extensions.facebook</extensionID>

	<!-- Needed on Android/iOS -->
	<extensionID>com.myflashlab.air.extensions.dependency.overrideAir</extensionID>

	<!-- Needed on Android ONLY -->
	<extensionID>com.myflashlab.air.extensions.dependency.overrideAir</extensionID>
	<extensionID>com.myflashlab.air.extensions.dependency.androidx.arch</extensionID>
	<extensionID>com.myflashlab.air.extensions.dependency.androidx.cardview</extensionID>
	<extensionID>com.myflashlab.air.extensions.dependency.androidx.core</extensionID>
	<extensionID>com.myflashlab.air.extensions.dependency.androidx.design</extensionID>
	<extensionID>com.myflashlab.air.extensions.dependency.androidx.lifecycle</extensionID>
	<extensionID>com.myflashlab.air.extensions.dependency.androidx.utils</extensionID>

  </extensions>

Requirements: