How to connect Facebook SDK to your application? How to register the application on https://developers.facebook.com ? How to get started with the Facebook SDK?
- As far as I understand, now you do not need to enter either the package name, or activation, or Key Hash. By the way, you can tell me, I can’t send them my billing information, they are unable to accept payment information at the moment, I don’t understand what the problem might be. - Denis Zharikov
- As for payments, I will not tell you anything, I have not come across it. Regarding the changes, nothing has changed on developers.facebook.com/quickstarts . In the examples on github.com/facebook/facebook-android-sdk/tree/master/samples - this is also the old way. - Alex Kisel 2:21 pm
1 answer
Minimum project setup to start working with the Facebook SDK according to the documentation :
1) In your project open your_app -> Gradle Scripts -> build.gradle (Project) and add the following repository to the buildscript { repositories {}} section to download the SDK from the Maven Central Repository:
mavenCentral() 2) Now in the build.gradle (Module: app) add compilation instructions to the dependencies{} section of the library necessary for working with Facebook:
compile 'com.facebook.android:facebook-android-sdk:4.28.0' or for Gradle v3.0 :
implementation 'com.facebook.android:facebook-android-sdk:4.28.0' implementation - in order not to compile all the dependencies, for more information about the difference compile and implementation see here
3) In the manifest file ( AndroidManifest.xml ), before the <application> tag <application> declare permission to access the Internet:
<uses-permission android:name="android.permission.INTERNET"/> 4) Now inside the <application> add ApplicationId :
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id" /> 5) We register inside the tags <activity> <intent-filter> … scheme (type) of data that will be taken by the Activity :
<data android:scheme="@string/facebook_login_protocol_scheme" /> 6) In res/values/strings.xml add two lines, the values (ie, ApplicationId and the data schema) in which we write later:
<string name="facebook_app_id">add late</string> <string name="facebook_login_protocol_scheme">add late</string> 7) Now we will get the Key Hash in Base64 format according to this documentation . In Activity we temporarily write the code:
//... public final String TAG = this.getClass().getSimpleName(); protected void onCreate(Bundle savedInstanceState) { //... printKeyHash(); } private void printKeyHash() { try { PackageInfo info = getPackageManager() .getPackageInfo("io.github.ziginsider.facebooksdkdemo", PackageManager.GET_SIGNATURES); for (Signature signature:info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); Log.d(TAG, "KeyHash: " + Base64.encodeToString(md.digest(),Base64.DEFAULT)); } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } } //... 8 ) Run the application and find the Key Hash in the logs:
9 ) If you are not yet registered as a developer on Facebook, then we go to the developers.facebook.com website and in the upper right corner we find the start button, click, follow the instructions and get to the application control panel.
Further Настройки(Settings) -> Основное(Basic) . Below we see the button + Add platform (+ Add platform) . Click. Adding Android . In the Название пакета Google Play(Google Play package name) field, enter your package (example io.github.ziginsider.facebooksdkdemo ). In the Название класса(Class name) field, the full class name of the Activity (example io.github.ziginsider.facebooksdkdemo.MainActivity ). In the Key хэш-адреса(Key Hashes) field хэш-адреса(Key Hashes) enter the previously received Key Hash .
Save the changes.
10) Next, take the Идентификатор приложения(App ID) and write it in the values of res/values/strings.xml . For example:
<string name="facebook_app_id">383374132098267</string> <string name="facebook_login_protocol_scheme">fb383374132098267</string> In the second line, simply add “fb” before the identifier.
Now your application can work with Facebook.
More: a small tutorial in Russian on working with the Facebook SDK.
- Good afternoon, now like Facebook has changed the site, can you update the instructions for working with them? - Denis Zharikov
- Good afternoon. I have not worked with the Facebook SDK for a long time, and a quick glance did not reveal any significant differences from this instruction. Could you please indicate what the specific inconsistencies are? - Alex Kisel

