Udonis

How to Set Up Facebook SDK in Android Studio and Xcode

How to Set Up Facebook SDK in Android Studio and Xcode

Looking for a guide on how to connect your app with Facebook?

Well, your search ends here.

In this post, we’ll tell you all you need to know about setting up Facebook SDK for Android and for iOS

So pull up a chair and read about it below.

What is Facebook SDK?

Facebook SDK allows mobile app developers to integrate Facebook into their mobile apps. It makes it possible for a website or an app to integrate with Facebook and get access to several key features.

Facebook SDK includes:

Analytics

It provides access to aggregated and anonymized data, so you can analyze how people are interacting with your app.

Login

It allows people to sign in to your app with their Facebook credentials. This is completely safe, and the best thing – it’s convenient.

Account Kit

If you implement an account kit, it will let users authenticate their identity by using their phone number or email address only.

Ads

If you want to monetize your app, you can use this feature to get ad revenue. It allows you to create and run ad campaigns within your app and earn money.

App Events

It allows you to track what users are doing within your app. You can use this information to evaluate the effectiveness of your mobile app ads or to identify the users who are most likely to respond to your ads.

App Links

When you set up App Links, you can control what happens when someone taps on one of the links shared through your app. That person may be redirected to your website or to specific content in your app. If someone does not have your app installed, they will be redirected to your app store page.

Graph API

By integrating Facebook Graph API, you can:

  • Get data in and out of Facebook’s social graph;
  • Query data;
  • Post stories;
  • Upload photos;
  • Perform many other tasks…

Tools You Will Need

Facebook Developer Account

You can find it here. In case you don’t have one, now is the time to register.

Facebook Ad Account

You can find it here. In case you don’t have one, you’ll need it for this.

Step 1: Configure Your Facebook App

Configure Your Facebook App for Android

First, log into Facebook developer account and do the following:

  1. Go to the App Dashboard;
  2. Click My Apps and create a new app;
  3. Go to Settings > Basic to see the App Details Panel with your App ID, App Secret as well as other app details.

If you want to set up your app for advertising, add the following details:

  • App Domains – Provide the Google Play Store URL of your app.
  • Privacy Policy Link – Add a Privacy PolicyURL, this is required to make your app public.
  • Terms of Service Link – Add a Terms of Service URL, this is another Google Play requirement.
  • Platform – Scroll down the Settings panel to add the android platform and put in the following app information:
  • Package name;
  • Class name;
  • Developmentand Release Key Hashes

Configure Your Facebook App for iOS

First, log into Facebook developer account and do the following:

  1. Go to the App Dashboard;
  2. Click My Apps and create a new app;
  3. Go to Settings > Basic to see the App Details Panel with your App ID, App Secret as well as other app details.

After that, you will be able to add an iOS platform to your Facebook app.

facebook developer account

Once you add the platform, you need to put in the following app info.

bundle id

Make sure that you add this to the Bundle ID field on the Facebook Apps Dashboard and save your app.

Step 2: Configure Your Facebook Ad Account with Your App

To run ads in your app and measure installs in the Ads Manager, you need to associate at least one Ad Account with your app.

In the App Dashboard, click Settings > Advanced.

You can get your ad account IDs from Ads Manager.

If you have a business account in Authorized Businesses, add your Business Manager ID. You can find your Business Manager ID in the URL of your Business Manager.

Step 3: Integrate the Facebook SDK

Integrate the Facebook SDK in Your Android App

Follow these steps:

  • Open android studio;
  • Start a new android studio project;
  • Click Empty Activity;
  • Click Next.

create new project

  • Type in the app Name;
  • Make the Minimum SDK to be API 19: Android 4.4 (KitKat) or higher;
  • Click Finish.

configure project

In your project:

  • Open Gradle Scripts;
  • Opengradle (Project level);
  • Add this line[php]mavenCentral()[/php]

    to thebuildscript { repositories {}} section to download the SDK from the Maven Central repository.

gradle scripts

In your project:

  • Open Gradle Scripts;
  • Go togradle (Module: app level file);
  • Add the following dependence to thedependencies{} section to implement the latest version of the Facebook SDK:

[php]implementation ‘com.facebook.android:facebook-android-sdk:5.15.3′[/php]

app id

After that:

  • Open /app/res/values/strings.xmlfile;
  • Add the following code (remember to replace[APP_ID] with your app ID):

[php]
<string name=”fb_application_id”>[YOUR_APP_ID]</string>
<string name=”fb_login_protocol_scheme”>[YOUR_APP_ID]</string>
[/php]

meta data

  • Open the manifests file “app/manifests/AndroidManifest.xml”;
  • Add ameta-data element in to the application tag:

[php]
<meta-data android:name=”com.facebook.sdk.ApplicationId” android:value=”@string/fk_app_id”/>
[/php]

manifests

  • Open thexml file;
  • Add the followinguses-permission tag before the application tag:

[php]<uses-permission android:name=”android.permission.INTERNET”/>[/php]

uses permission

After that, rebuild your project.

rebuild project

Now you are connected to the official Facebook SDK and have access to a wide range of new features.

Integrate the Facebook SDK in Your iOS App

  1. Open Xcode, click on File > Swift Packages > Add Package Dependency;
  2. The following dialog will appear. Once it does, enter the repository; URL: https://github.com/facebook/facebook-ios-sdk.

package options

  1. Under Version, select Up to Next Major with the default option;
  2. Complete the prompts to select the libraries you want to use in your project and click next.

add package facebook sdk

Steps 4 to 6 apply to iOS only.

Step 4: Configure the Project in Xcode

To configure the project follow these steps.

    1. Right-click info.plist, and choose Open As Source Code.
    2. Add the following XML snippet into the body of your file (<dict>…</dict>) as show in image.

[xml]
&amp;lt;key&amp;gt;CFBundleURLTypes&amp;lt;/key&amp;gt;
&amp;lt;array&amp;gt;
&amp;lt;dict&amp;gt;
&amp;lt;key&amp;gt;CFBundleURLSchemes&amp;lt;/key&amp;gt;
&amp;lt;array&amp;gt;
&amp;lt;string&amp;gt;fb[APP_ID]&amp;lt;/string&amp;gt;
&amp;lt;/array&amp;gt;
&amp;lt;/dict&amp;gt;
&amp;lt;/array&amp;gt;
&amp;lt;key&amp;gt;FacebookAppID&amp;lt;/key&amp;gt;
&amp;lt;string&amp;gt;[APP_ID]&amp;lt;/string&amp;gt;
&amp;lt;key&amp;gt;FacebookDisplayName&amp;lt;/key&amp;gt;
&amp;lt;string&amp;gt;[APP_NAME]&amp;lt;/string&amp;gt;
[/xml]

 

  1. To use any of the Facebook dialogs (e.g., Login, Share, App Invites, etc.) that can perform an app switch to Facebook apps, your application’sinfo.plistalso needs to include: <dict>…</dict>).

[xml]
&amp;lt;key&amp;gt;LSApplicationQueriesSchemes&amp;lt;/key&amp;gt;
&amp;lt;array&amp;gt;
&amp;lt;string&amp;gt;fbapi&amp;lt;/string&amp;gt;
&amp;lt;string&amp;gt;fbapi20130214&amp;lt;/string&amp;gt;
&amp;lt;string&amp;gt;fbapi20130410&amp;lt;/string&amp;gt;
&amp;lt;string&amp;gt;fbapi20130702&amp;lt;/string&amp;gt;
&amp;lt;string&amp;gt;fbapi20131010&amp;lt;/string&amp;gt;
&amp;lt;string&amp;gt;fbapi20131219&amp;lt;/string&amp;gt;
&amp;lt;string&amp;gt;fbapi20140410&amp;lt;/string&amp;gt;
&amp;lt;string&amp;gt;fbapi20140116&amp;lt;/string&amp;gt;
&amp;lt;string&amp;gt;fbapi20150313&amp;lt;/string&amp;gt;
&amp;lt;string&amp;gt;fbapi20150629&amp;lt;/string&amp;gt;
&amp;lt;string&amp;gt;fbapi20160328&amp;lt;/string&amp;gt;
&amp;lt;string&amp;gt;fbauth&amp;lt;/string&amp;gt;
&amp;lt;string&amp;gt;fb-messenger-share-api&amp;lt;/string&amp;gt;
&amp;lt;string&amp;gt;fbauth2&amp;lt;/string&amp;gt;
&amp;lt;string&amp;gt;fbshareextension&amp;lt;/string&amp;gt;
&amp;lt;/array&amp;gt;[/xml]

configure project xcode

  1. In <array><string>that’s in the key[CFBundleURLSchemes], replace [YOUR_APP_ID] with your App ID.
  2. In <string>that’s in the key FacebookAppID, replace [YOUR_APP_ID]with your App ID.
  3. In<string>that’s in the key FacebookDisplayName, replace [YOUR_APP_NAME] with the name of your app.

Step 5: Connect the App Delegate

Replace the code in AppDelegate.swift with the following code. This code initializes the SDK when your app launches and allows the SDK to handle results from the native Facebook app when you perform a Login or Share action:

[php]
//  AppDelegate.swift
import UIKit
import FBSDKCoreKit
@UIApplicationMain

class AppDelegate: UIResponder, UIApplicationDelegate {

func application(

_ application: UIApplication,

didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?

) -&amp;gt; Bool {

ApplicationDelegate.shared.application(

application,

didFinishLaunchingWithOptions: launchOptions

)

return true  }

func application(

_ app: UIApplication,

open url: URL,

options: [UIApplication.OpenURLOptionsKey : Any] = [:]

) -&amp;gt; Bool {

ApplicationDelegate.shared.application(

app,

open: url,

sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,

annotation: options[UIApplication.OpenURLOptionsKey.annotation]

)

}

}[/php]

If you are using iOS 13 or above please add the following method to your SceneDelegate:

[php]
//  SceneDelegate.swift

func scene(_ scene: UIScene, openURLContexts URLContexts: Set&amp;amp;lt;UIOpenURLContext&amp;amp;gt;) {
guard let url = URLContexts.first?.url else {
return
}

ApplicationDelegate.shared.application(
UIApplication.shared,
open: url,
sourceApplication: nil,
annotation: [UIApplication.OpenURLOptionsKey.annotation]
)
}

[/php]

connect app delegate

Step 6: Build and Run Your Project in the Simulator

In Xcode, first select an iOS simulator and then click Run. Xcode will build the project and then launch the most recent version of your app running in Simulator.

Now you are connected to the official Facebook SDK and have access to a wide range of new features.

That’s It, Folks

Did you find this post helpful? Is there anything you’d like to add?

Let us know in the comments below.

We love writing about app development tips and tricks, so let us know what you would like to read about next.

Udonis

About Udonis

Udonis is an independent full-service mobile marketing agency that acquired more than 300,000,000 users for mobile games since 2018.

Visit udonis.co

Categories

Mobile Games

Mobile Marketing

Mobile Apps

Mobile Game Dissections

Digital Marketing

Monetization

Blockchain

User Acquisition

Mobile Game Market

Recently updated

Facebook Ads

Advertising

Blockchain Game Dissections

Case Study

How to Integrate Facebook Ads Integration Into Your App

How to Integrate Facebook Ads Integration Into Your App

Want to learn how to integrate Facebook Ads into Android and iOS apps? In this easy-to-follow guide, we show you how!
eCPMs for Rewarded Video, Interstitial & Banner Ads

eCPMs for Rewarded Video, Interstitial & Banner Ads

In this article, we reveal eCPMs for rewarded video ads, interstitial ads, and banner ads across all world regions. Read about it now!
Project Makeover Dissection: How It Brought Match-3 Back to Life

Project Makeover Dissection: How It Brought Match-3 Back to Life

How did Project Makeover reach the top charts in the competitive match-3 market? Find out in our in-depth dissection!
Top 13 Mobile Ad Mediation Platforms For Mobile Apps & Games

Top 13 Mobile Ad Mediation Platforms For Mobile Apps & Games

Want to monetize your app and get revenue from ads? You should consider working with ad mediation platforms. Find out which are the top ones!
How to Integrate Facebook Ads Integration Into Your App

How to Integrate Facebook Ads Integration Into Your App

Want to learn how to integrate Facebook Ads into Android and iOS apps? In this easy-to-follow guide, we show you how!
eCPMs for Rewarded Video, Interstitial & Banner Ads

eCPMs for Rewarded Video, Interstitial & Banner Ads

In this article, we reveal eCPMs for rewarded video ads, interstitial ads, and banner ads across all world regions. Read about it now!
Project Makeover Dissection: How It Brought Match-3 Back to Life

Project Makeover Dissection: How It Brought Match-3 Back to Life

How did Project Makeover reach the top charts in the competitive match-3 market? Find out in our in-depth dissection!
Top 13 Mobile Ad Mediation Platforms For Mobile Apps & Games

Top 13 Mobile Ad Mediation Platforms For Mobile Apps & Games

Want to monetize your app and get revenue from ads? You should consider working with ad mediation platforms. Find out which are the top ones!

Comments

Read more