Facebook登录 AndroidStudio
简介
接入SDK-1
一、Add Facebook SDK to Your ProjectTo use Facebook SDK in a project, add it as a build dependency and import it. If you are starting a new project, follow all the steps below. To add Facebook SDK to an existing project, start with step 3.1. Go to Android Studio | New Project | Minimum SDK2. Select "API 15: Android 4.0.3" or higher and create your new project.3. In your project, open your_app | Gradle Scripts | build.gradle4. Add the Maven Central Repository to build.gradle before dependencies:repositories {mavenCentral()}5. Add compile 'com.facebook.android:facebook-android-sdk:[4,5)' to your build.gradle dependencies.6. Build your project.7. Import Facebook SDK into your app and init it:import com.facebook.FacebookSdk;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);FacebookSdk.sdkInitialize(getApplicationContext());// Initialize the SDK before executing any other operations, especially, if you're using Facebook UI elements.}二、Add Facebook App IDAdd your Facebook App ID to your app and update your Android manifest.1. Open your strings.xml file, for example: /app/src/main/res/values/strings.xml.2. Add a new string with the name facebook_app_id containing the value of your Facebook App ID:<string name="facebook_app_id">1157270487625628</string>3. Open AndroidManifest.xml.4. Add a uses-permission element to the manifest:<uses-permission android:name="android.permission.INTERNET"/>5. Add a meta-data element to the application element:<application android:label="@string/app_name" ...><meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/></application>三、Tell us about your Android projectPackage NameYour package name uniquely identifies your Android app. We use this to let people download your app from Google Play if they don't have it installed. You can find this in your Android Manifestcom.dongbai.mm.xiuDefault Activity Class NameThis is the fully qualified class name of the activity that handles deep linking. We use this when we deep link into your app from the Facebook app. You can also find this in your Android Manifestcom.lokinfo.m95xiu.WelcomeActivity四、Add your development and release key hashesTo ensure the authenticity准确 of the interactions互动 between your app and Facebook, you need to supply us with the Android key hash for your development environment. If your app has already been published, you should add your release key hash too.You'll have a unique development key hash for each Android development environment. To generate a development key hash, on Mac, run the following command:keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64On Windows, run this command:keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | openssl sha1 -binary | openssl base64【4SrCEIfuM++ddKXQh34fqEsxXsI=】This command will generate a 28-character key hash unique to your development environment. Copy and paste it into the field below. You will need to provide a development key hash for the development environment of each person who works on your app.If your app has already been published, you should also add a hash of your release key.Android apps must be digitally signed with a release key before you can upload them to the store. 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:keytool -exportcert -alias YOUR_RELEASE_KEY_ALIAS -keystore YOUR_RELEASE_KEY_PATH | openssl sha1 -binary | openssl base64This will generate a 28-character string that you should copy and paste into the field below. Also, see the Android documentation for signing your apps.五、Track App Installs and App OpensApp Events let you measure installs on your mobile app ads, create high value audiences观众 for targeting, and view analytics including user demographics统计学. To automatically log app activation events, add the following code to the onCreate() method of your app's Application class:FacebookSdk.sdkInitialize(getApplicationContext());AppEventsLogger.activateApp(this);Now, when people install or engage with your app, you'll see this data reflected in your app's Insights dashboard.Next StepsCongratulations! You have added the Facebook SDK to your project. You are now in the next stage in integrating your app with Facebook. What do you want to do next? Skip to Developer Dashboard or Documentation
接入SDK-2
Android Studio SetupTo use Facebook SDK in a project, add it as a build dependency and import it.1. Go to Android Studio | New Project | Minimum SDK2. Select API 15: Android 4.0.3 or higher and create your new project.3. After you create a new project, open your_app | build.gradle4. Add this to Module-level /app/build.gradle before dependencies:repositories {mavenCentral()}5. Add the compile dependency with the latest version of the Facebook SDK in the build.gradle file:dependencies {compile 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.Using the Facebook SDK with MavenYou can declare the Maven dependency依赖关系 with the latest最新 available version of the Android SDK:<dependency><groupId>com.facebook.android</groupId><artifactId>facebook-android-sdk</artifactId><version>PUT_LATEST_VERSION_HERE</version></dependency>Troubleshooting疑难解答 Sample AppsIf 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: OrcaServiceQueue(504):com.facebook.orca.protocol.base.ApiException: remote_app_id does not match stored id
- 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.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():@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);try {PackageInfo info = getPackageManager().getPackageInfo("com.facebook.samples.hellofacebook", PackageManager.GET_SIGNATURES);for (Signature signature : info.signatures) {MessageDigest md = MessageDigest.getInstance("SHA");md.update(signature.toByteArray());Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));}} catch (NameNotFoundException e) {} catch (NoSuchAlgorithmException e) {}Save your changes and re-run the sample. Check your logcat output for a message similar to this:12-20 10:47:37.747: D/KeyHash:(936): 478uEnKQV+fMQT8Dy4AKvHkYibo=Save the key hash in your developer profile. Re-run the samples and verify that you can log in successfully
Facebook登录 AndroidStudio的更多相关文章
- 集成Facebook SDK之Facebook登录
前言 这几天应公司需求,需要在项目中接入facebook的登录,现在闲下来后再次巩固一下! 准备工作 保证自己的网络已经翻墙,能够进入Facebook网页 准备一个FB的开发者账号,如果没有可以免费申 ...
- Android 应用程序集成FaceBook 登录及二次封装
1.首先在Facebook 开发者平台注册一个账号 https://developers.facebook.com/ 开发者后台 https://developers.facebook.com/ap ...
- 在Android上实现使用Facebook登录(基于Facebook SDK 3.5)
准备工作: 1. Facebook帐号,国内开发者需要一个vpn帐号(网页可以浏览,手机可以访问) 2. 使用Facebook的SDK做应用需要一个Key Hashes值. 2 ...
- 很酷的CSS3仿Facebook登录表单
原文:很酷的CSS3仿Facebook登录表单 今天看到一款很不错的CSS3登录表单,外观是仿Facebook的登录表单,还挺不错的,另外也支持简单的表单输入框验证.下图是表单的效果图: 我们也可以在 ...
- android应用集成facebook登录
之前都是做国内的应用开发,没有用过国外的三方登录,比如谷歌登录.facebok登录,最近参与了一个海外的支付相关的项目,调研了一下谷歌登录和facebook登录,其实调研之后觉得也是很简单的,尤其 ...
- ASP.NET5使用FaceBook登录
原版教程 使用VS2015创建Web应用: 此教程使用的是FaceBook账号登录,需要添加相关的类,打开Nuget: 搜索Microsoft.AspNet.Authentication.Facebo ...
- Android平台接入Facebook登录
官方教程地址: https://developers.facebook.com/docs/android/getting-started 开发环境为Android Studio,官方要求SDK最低版本 ...
- facebook 登录开发记录
1.注册一个 facebook 的账号 2.进入 facebook 开发者的网站.(也可以在 facebook 登录后,点击自己的名字进入用户信息页面,在该页面的底部有个“更多”的链接,点击进去会看到 ...
- Android 版 Facebook 登录
Android 版 Facebook SDK 让用户可以通过 Facebook 登录注册您的应用.通过 Facebook 登录您的应用时,用户可以向应用授予权限,以便您可以检索信息或以用户的身份在 F ...
随机推荐
- java.sql.SQLException: ORA-00604: 递归 SQL 级别 1 出现错误
后台报出如下错误: Caused by: java.sql.SQLException: ORA-00604: 递归 SQL 级别 1 出现错误 ORA-01000: 超出打开游标的最大数 ORA-00 ...
- Objective-C学习篇07—NSArray与NSMutableArray
大纲 NSArray NSMutableArray 快速枚举 NSArray NSArray是一个静态数组,也就是一个不可变数组,一旦创建以后,就不能进行添加,删除或者修改其中的元素.NSArray继 ...
- xAML中一些控件的用法学习
首先,介绍一些比较简单的设计,这些可以直接通过拖拽实现.如下例子: <Window x:Class="wpf1.MainWindow" xmlns="http:// ...
- oracle 空置排在最后显示
nulls last select * from emp order by comm select * from emp order by comm desc select * from emp or ...
- 高放的c++学习笔记之关联容器
标准库提供8个关联容器 按关键字有序保存有(红黑树实现) set map multset 关键字可重复出现的set multimap 关键字可重复出现的map 无序保存 哈希实现 unorderre ...
- java rmi 使用方法
server package Server; import java.rmi.Naming; import java.rmi.RMISecurityManager; import java.rmi.r ...
- 《Linux内核分析》 week8作业-Linux加载和启动一个可执行程序
一.ELF文件格式 ELF(Executable and Linking Format)是x86 Linux系统下常用的目标文件格式,有三种主要类型: 适于连接的可重定位文件,可与其他目标文件一起创建 ...
- IE9的BUG?jQuery的BUG?
本文转载自http://big-student.iteye.com/blog/1898213 在IE9和IE10中,当对一个html的样式初始了一个很大的left或者top时,使用jQuery的off ...
- Yum 安装 zabbix...
环境:centos6_64 Mysql环境.禁用iptable selinux 安装基础包: 需要安装LAMP.自己安装吧...不会的请移步...LAMP rpm -ivh http://repo.z ...
- Java中解析XML的四种方法
XML现在已经成为一种通用的数据交换格式,它的平台无关性,语言无关性,系统无关性,给数据集成与交互带来了极大的方便.对于XML本身的语法知识与技术细节,需要阅读相关的技术文献,这里面包括的内容有DOM ...
