- Getting Started with the Facebook SDK for Android
- Quick Start
- Android Studio Setup
- Add Your Facebook App ID and Client Token
- Sending Images or Videos
- Running Sample Apps
- Create a Development Key Hash
- Create a Release Key Hash
- Use the Facebook SDK for Android with Maven
- Troubleshooting Sample Apps
- How to Get Key Hashes for Android App Facebook Integration
- 1. Using OpenSSL and command prompt
- 2. Using a method call from android code
- Хеш-ключ для Facebook для Андроид СДК
- 9 ответов
- Это пример того, как получить хэш ключа из хранилища ключей:
- Это документ о том, как установите Key Hash на Facebook :
- How to Get Key Hashes for Android App Facebook Integration
- 1. Using OpenSSL and command prompt
- 2. Using a method call from android code
Getting Started with the Facebook SDK for Android
This documentation explains how to get started integrating your Android app with Facebook by using the Facebook SDK for Android. The current version of the Facebook SDK for Android is version 12.0.0 and requires the Android API 15. For more information about versions and features, see Facebook SDK for Android.
Beginning with SDK v13.0, set to release in early 2022, a Client Token will be required for all calls to the Graph API.
You can set up your app to use the Facebook SDK for Android in the following ways:
- By using the Quick Start.
- By setting up your project with the Facebook SDK for Android.
Quick Start
To get a Facebook App ID, configure your app’s settings, and import the Facebook SDK for Android, click on the button below and follow the instructions.
Android Studio Setup
To use the Facebook SDK in an Android Studio project, add the SDK as a build dependency and import the SDK.
- Go to Android Studio | New Project | Minimum SDK.
- Select API 15: Android 4.0.3 (IceCreamSandwich) or higher and create your new project.
- After you create a new project, open Gradle Scripts | build.gradle (Project: and do the following:
- Add the following to the buildscript < repositories <>> section of the build.gradle (Project) file:
- Save and close build.gradle (Project: ) .
- Open Gradle Scripts | build.gradle (Module: app) and do the following:
- Add the following to the dependencies <> section of your build.gradle (module: app) file to compile the latest version of the Facebook SDK for Android:
When you use the Facebook SDK, some events in your app are automatically logged and collected unless you disable automatic event logging. For details about what information is collected and how to disable automatic event logging, see Automatic App Event Logging.
Add Your Facebook App ID and Client Token
Add your Facebook App ID and Client Token to your project’s strings file and update your Android manifest:
1. Open your /app/res/values/strings.xml file.
2. Add a string element with the name attribute facebook_app_id and value as your Facebook App ID to the file. For example
3. Open /app/manifests/AndroidManifest.xml
4. Add a uses-permission element to the manifest:
5. Add a meta-data element to the application element:
Sending Images or Videos
If you’re sharing links, images or video via the Facebook for Android app, you also need to declare the FacebookContentProvider in the manifest.
Append your app id to the end of the authorities value. For example if your Facebook app id is 1234 , the declaration looks like:
Running Sample Apps
The following samples come with the Facebook SDK for Android:
- HelloFacebookSample — Demonstrates profile access, status updates and photo upload.
- RPSSample — Use Native Share Dialog, Open Graph publishing, pickers, invites, and deep linking.
- Scrumptious — Login, requests, pickers, picture uploads, and Open Graph publishing.
You can experiment with samples by importing the Facebook SDK into an Android Studio project. The samples have a project dependency rather than a central repository dependency via maven central or jcenter. This is so that when a local copy of the SDK gets updates, the samples reflect the changes.
To run samples apps quickly, you can generate key hashes for your development environments. Add these to your Facebook developer profile for the sample apps. Keytool, for generating the key hashes, is included with the Java SE Development Kit (JDK) that you installed as part of setting up your development environment. OpenSSL is available for download from OpenSSL.
On Windows, you need the following:
Run the following command in a command prompt in the Java SDK folder. This generates a 28 character string.
Go to the Facebook Developer site. Log into Facebook and, using the dropdown menu in the top-right, go to Developer Settings:
In your developer settings, select Sample App from the menu, and add and save your key hash into your profile:
You can add multiple key hashes if you develop with multiple machines.
You can now compile and run all of the samples — including those that use Facebook Login.
Create a Development Key Hash
Facebook uses the key hash to authenticate interactions between your app and the Facebook app. If you run apps that use Facebook Login, you need to add your Android development key hash to your Facebook developer profile.
For the version of your app that you release to you also need to generate and set a Release Key Hash.
On either OS X or Windows you can get a key hash by generating it or by using the value returned by Settings.getApplicationSignature(Context) . For instructions, see Running Sample Apps .
Create a Release Key Hash
To authenticate the exchange of information between your app and the Facebook, you need to generate a release key hash and add this to the Android settings within your Facebook App ID. Without this, your Facebook integration may not work properly when you release your app to the store.
In a previous step, you should have updated your Facebook Developer Settings with the key hashes for your development environments.
When publishing your app, it is typically signed with a different signature to your development environment. Therefore, you want to make sure you create a Release Key Hash and add this to the Android settings for Facebook App ID.
To generate a hash of your release key, run the following command on Mac or Windows substituting your release key alias and the path to your keystore.
On Windows, you need the following:
Run the following command in a command prompt in the Java SDK folder:
Make sure to use the password that you set when you first created the release key.
This command should generate a 28 characher string. Copy and paste this Release Key Hash into your Facebook App ID’s Android settings.
You should also check that your Facebook App ID’s Android setting also contain the correct package name and main activity class for your Android package.
Use the Facebook SDK for Android with Maven
You can declare the Maven dependency with the latest available version of the Facebook SDK for Android.
Troubleshooting Sample Apps
If you have a problem running a sample app, it may be related to the key hash. You may see one of the following scenarios:
- A native Login Dialog appears but after accepting the permissions you are still in a logged out state. The logcat also contains an exception:
- A non-native Login Dialog appears with an error message: »..App is Misconfigured for facebook login. ».
Check your key hash and you can make sure you use the correct key hash. I
You can also manually modify the sample code to use the right key hash. For example in HelloFacebookSampleActivity class make a temporary change to the onCreate() :
Save your changes and re-run the sample. Check your logcat output for a message similar to this:
Save the key hash in your developer profile. Re-run the samples and verify that you can log in successfully.
Источник
How to Get Key Hashes for Android App Facebook Integration
This section of the tutorial explains you how to get Key Hashes for Android Facebook app. Facebook SDK integration to android require an key hash configuration.
While integrating Facebook SDK, we need to configure Facebook API console with Key Hash. If key hash is missing you will get App mis-configured error in Facebook dashboard.
Download the facebook-android-sdk and configured a new app. In the application settings enable “Native android app” and enable for Facebook login and deep linking. It asks for key hashes, and I’m stuck. After spending a generous amount of time, I have found two solutions to get the key hashes.
1. Using OpenSSL and command prompt
- Download openssl from Google code (If you have a 64 bit machine you must download openssl-0.9.8e X64 not the latest version)
- Extract it. Create a folder- OpenSSL in C: / and copy all files here
- Find “debug.keystore” file path. Most likely it will be inside “C:\Users\\.android” folder. However, if you still don’t find then perform a search. I am sure you are lucky enough to get it.
- Find keytool.exe path. It will be inside your java/bin directory. In my system it is under “C:\Program Files\Java\jdk1.6.0_30\bin”
- Open command prompt (Run-> cmd->start) and go to java /bin folder (cd “C:\Program Files\Java\jdk1.6.0_30\bin” command will do it for you)
- Now you run the below command.
- Provide password (android), as when you are prompted. You are done. It will generate you the key-hash
2. Using a method call from android code
Using below code snippet, you can get the hash code.
You may use any of the above methods to generate the key hash for your facebook app.
Источник
Хеш-ключ для Facebook для Андроид СДК
Я не могу понять, как получить ключевой хэш, необходимый для использования Facebook Android SDK. Я понял, что могу использовать keytool С помощью следующих команд:
единственная проблема в том, что я понятия не имею, куда вставить это, я попробовал через командные окна (win7), и я попытался открыть файл keytool.исполняемый.
9 ответов
- Загрузите и установите OpenSSL из http://slproweb.com/products/Win32OpenSSL.html на основе windows 32 или 64 бит.(Примечание: Загрузите и установите первый visual C++ 208 redisributable с этого сайта также)
- поместите каталог bin установленного OpenSSL в путь windows.
- Откройте командную строку и перейдите к C:\Users
.android - теперь поставьте эту команду на cmd»keytool-exportcert-псевдоним androiddebugkey-хранилище ключей отлаживать.keystore | openssl sha1-binary / openssl base64«.(см. https://developers.facebook.com/docs/android/getting-started#samples)
- теперь введите пароль «facebook» без двойных кавычек.
- теперь будет создан хэш-ключ
- наконец перейдите на сайт разработчика Facebook. Убедитесь, что вы вошли в Facebook и, используя выпадающее меню в правом верхнем углу, перейдите в «настройки разработчика»:
- Как только вы в настройки разработчика, выберите «пример приложения» из навигации слева, а также добавить и сохранить хэш ключа в свой профиль:
вы можете установить Open SSL из здесь, это должно заставить вашу команду работать
Я создал пакетный скрипт facebookkeydebug.летучая мышь!—3—>, которые возвращают желаемый хэш ключа Facebook. Просто отредактируйте скрипт, установите правильные пути, имя хранилища ключей и запустите его.
EDIT: я опубликовал РЕПО с некоторыми пакетными скриптами для подписания и получения ключей сертификатов в Windows:https://github.com/petrnohejl/Android-Scripts
вы можете использовать код ниже, чтобы получить хэш-ключ :
чтобы сделать вещи легче —
это должно предоставить вам необходимые отпечатки пальцев, без хлопот установки openssl.
Это пример того, как получить хэш ключа из хранилища ключей:
сначала нам нужно получить пути:
путь Java: C:\Program файлы\Java\jdk1.6.0_35\jre\bin
открыть путь SSL: C:\OpenSSL-Win32\bin
Путь Хранилища Ключей: C:\Data\ANDROID\KEYSTORE\
2) затем перейдите в командную строку и тип:
3) затем введите :
keytool.ехе -exportcert -псевдоним [псевдоним] -хранилище [хранилище Path]\debug.хранилище ключей / [открыть путь SSL]\openssl sha1-binary | [открыть Путь SSL]\bin\openssl base64
4) пароль вашего хранилища ключей должен быть обязательным, а затем у вас есть Hash Key связано с вашим хранилищем ключей Android.
Это документ о том, как установите Key Hash на Facebook :
необходимо открыть окно командной строки. Перейдите в меню Пуск — >Выполнить и введите » cmd » и нажмите enter. Затем вы должны перейти к папке, где keytool is (если он не находится на вашем пути), а затем введите эту команду.
то есть, предполагая, что команда предназначена для windows, а не linux.
лучший способ-сгенерировать ключ-хэш с помощью кода:
вызовите этот метод один раз и сгенерируйте key-hash, enjoy
Источник
How to Get Key Hashes for Android App Facebook Integration
This section of the tutorial explains you how to get Key Hashes for Android Facebook app. Facebook SDK integration to android require an key hash configuration.
While integrating Facebook SDK, we need to configure Facebook API console with Key Hash. If key hash is missing you will get App mis-configured error in Facebook dashboard.
Download the facebook-android-sdk and configured a new app. In the application settings enable “Native android app” and enable for Facebook login and deep linking. It asks for key hashes, and I’m stuck. After spending a generous amount of time, I have found two solutions to get the key hashes.
1. Using OpenSSL and command prompt
- Download openssl from Google code (If you have a 64 bit machine you must download openssl-0.9.8e X64 not the latest version)
- Extract it. Create a folder- OpenSSL in C: / and copy all files here
- Find “debug.keystore” file path. Most likely it will be inside “C:\Users\\.android” folder. However, if you still don’t find then perform a search. I am sure you are lucky enough to get it.
- Find keytool.exe path. It will be inside your java/bin directory. In my system it is under “C:\Program Files\Java\jdk1.6.0_30\bin”
- Open command prompt (Run-> cmd->start) and go to java /bin folder (cd “C:\Program Files\Java\jdk1.6.0_30\bin” command will do it for you)
- Now you run the below command.
- Provide password (android), as when you are prompted. You are done. It will generate you the key-hash
2. Using a method call from android code
Using below code snippet, you can get the hash code.
You may use any of the above methods to generate the key hash for your facebook app.
Источник
- Add the following to the dependencies <> section of your build.gradle (module: app) file to compile the latest version of the Facebook SDK for Android: