background

Recently there was a need to access the FaceBook SDK. This is the first time to access the FaceBook SDK. Write it down and talk to people about it.

Pre – work

  1. Read the relevant documentation: developers.facebook.com/docs/androi…

  2. Enter the page of FaceBook Developer platform, create the corresponding app, and get the app AppId and AppSecret

  3. Fill in the software package name

  4. Get the key hash.

The key hash value is generated based on the signature of the application. For example, if your App, development environment and formal environment use different signatures, you will need to configure the corresponding key hash. If you do it from the command line, that’s fine, but Windows and MAC work differently. Personally, it is also convenient to encapsulate a method through code generation, and it is also convenient to call a method and print it out.

  1. Integrate the Facebook SDK according to the documentation.
  2. Configure the relevant information in AndroidManifest

Specific access of each function

The login

The document

Developers.facebook.com/docs/facebo…

The login process

A normal login process design looks something like this.

  1. When the user clicks the Facebook login button, the client App activates the Facebook App, and the user enters the login information on the Facebook page. After successful login, Facebook calls back the client and brings back the user’s Facebook information
  2. The client sends the user’s Token to the server, and the server invokes the Facebook token authentication interface to verify whether the token is valid
  3. If it works, then Facebook’s third-party login is successful.

The main code implementation

self-test

At this point, the main access related to FaceBook login is ok, and the accessToken is available on successful authorization. Then, information of FB users can be obtained through accessToken.

Deep links

Delayed deeplink on Facebook is aimed at advertising on Facebook. When users click the advertisement on Facebook client before the app is installed, they will first jump to Google Play to download the app, and then when they open the app for the first time, they will read the configured deeplink. Jump to the corresponding page.

For example, a user clicks on an advertisement of a beautiful woman on FaceBook and installs my app in Google Store. After opening the app, the user reads the configured Deeplink and directly jumps to the page of the list of beautiful women, giving the user a more smooth user physical examination.

The document

Developers.facebook.com/docs/app-ad…

Delayed deep linking

If you advertise to users who have not yet installed your app, you must use delayed deep linking. If you only serve ads to users who already have your app installed, you don’t need to add delayed deep linking.

self-test

There is an AD helper tool that makes it easy to debug deep links. Links:Developers.facebook.com/tools/app-a…Fill in deeplink for the test and hit Send. You can receive a notification on your phone and tap to jump to deeplink.

Facebook Analytics

Analyze all kinds of data through Facebook Analytics. The following figure shows the indicators of interest.

Corresponding to the document

Developers.facebook.com/docs/analyt…

Application events reported by default

By default, after the FaceBook SDK is plugged in. Some app events are automatically recorded, collected and reported to FaceBook. App Install – App Install – App Launch

Custom events

Simply create an AppEventsLogger to log events.

self-test

The next step is to verify that the access is successful. The event management tool is used to debug and report events in real time. Event Management Platform: www.facebook.com/events_mana… Start the application and perform related operations. You can view corresponding events reported in real time.

Initialization of the Facebook SDK

The FacebookInitProvider automatically initializes

  • By default, the FaceBook SDK does not require us to manually call sdkInitialize() to initialize it.
  • FaceBook uses a custom FacebookInitProvider to initialize the Application at startup by calling sdkInitialize() after getting the context in the onCreate method.

The FacebookInitProvider delays initialization

While this approach is convenient, the ContentProvider initializes the APP during startup, increasing the startup time. So we can lazily initialize it. The solution

  • Use tools:node=”remove” to remove the provider from the Facebook SDK. The resulting AndroidManifests file in the APK will not have the FacebookInitProvider and will not automatically initialize the ContentProvider when the application starts.
  • And then we can manually initialize it ourselves at the right time.

conclusion

  • Learn about FaceBook platform features and SDK access
  • Understand the merging rules of Android Manifest files