[Unity] Facebook SDK Example tutorials



Overview

1. Create Facebook App
2. Set Facebook App Key Hash
3. Install OpenSSL
4. Install JDK
5. Set environment variable
6. Download & import Unity Facebook SDK
7. Confirm Bundle ID & Keystore
8. Modify AndroidManifest Merge
9. Build!


Create Facebook App

First goto Facebook Developer Page to be a developer of Facebook, then goto
My Apps => Add a New App

[Unity] Facebook SDK

Select your platform

Usually we start from Android for Unity development, so the article example will also choose Android.

[Unity] Facebook SDK

Naming

Naming is the most difficult part…
Anyway, that’s consider a good name!

[Unity] Facebook SDK

Package & Activity Name

The default Activity class name for Unity is
com.unity3d.player.UnityPlayerActivity

[Unity] Facebook SDK

[Unity] Facebook SDK

Create Key Hashes

Details:How to generate Android Key Hash

The above article is generating on MacOS, if you’re using Windows just skip this step first.

[Unity] Facebook SDK

Create Complete

You will need your Facebook App ID in Unity.

[Unity] Facebook SDK

Download Facebook SDK

[Unity] Facebook SDK

Create new Unity project & import Facebook SDK

[Unity] Facebook SDK

Facebook Setting

Facebook => Edit Setting

[Unity] Facebook SDK

OpenSSL not found

Fill your Facebook App Id first, then expand Android Build Facebook Setting below, confirm is everything alright.

If you don’t install OpenSSL, you might have the following message:

OpenSSL not found. Make sure that OpenSSL is installed, and that it its in your path.

[Unity] Facebook SDK

Download Openssl-forwindows

[Unity] Facebook SDK

Install location

Copy the extract directory to wherever you want. I just put it into Program Files.

[Unity] Facebook SDK

Add OpenSSL path into environment variable

Then restart Unity.
Ex. C:\Program Files\OpenSSL\bin

[Unity] Facebook SDK

Keytool not found

After solving OpenSSL problem, you will meet another message if you don’t install JDK.

[Unity] Facebook SDK

Download JDK

[Unity] Facebook SDK

Add JDK environment variable

Just the same step like OpenSSL.
Ex. C:\Program Files\Java\jdk1.8.0_25\bin

[Unity] Facebook SDK

Confirm Bundle ID

Be sure it’s equals to the one in your Facebook Console.

[Unity] Facebook SDK

Set Scenes

Add all Example Scenes into Build Settings, put the MainMenu Scene for the first.

[Unity] Facebook SDK

Unable to merge android menifests

You might meet the final problem: Different version of Menifests.

[Unity] Facebook SDK

Error Log

You can see the minSdkVerion & targetSdkVersion in Log.

[Unity] Facebook SDK

SdkVersion Setting

Add SdkVersion into the Main Manifest.xml
Path: Assets/Plugins/Android/AndroidManifest.xml

[Unity] Facebook SDK

Login Facebook

Click the FB.Init button first.
Be sure to use your developer account.

[Unity] Facebook SDK[Unity] Facebook SDK

Publish test

[Unity] Facebook SDK[Unity] Facebook SDK


FacebookManager on Github

You can use FacebookManager on my Github for shortcut.

m_fbManager = new FBManager();
m_fbManager.LoginCompleteEvent += OnFBLoginComplete;
m_fbManager.ErrorEvent += OnFBError;

m_fbManager.Login();
m_fbManager.Snapshot( texture, title, fileName );



歡迎您留言與分享!(Welcome for comments or sharing!)

Related Post:

Tagged on: ,