Use the latest FaceBook SDK 3.0 in Android (I) to integrate FacebookSDK into the project

Source: Internet
Author: User
Tags openssl enc openssl sha1

As we all know, FaceBook is used by many people outside China, and is rarely used in China. If we are a programmer, we should continue to learn and learn, so that we can enrich ourselves. Who said no! Well, let's join in FaceBook's learning journey!

 

When you start to study, you should get a network that can overturn the wall. The domestic network cannot access the facebook website. You can get a "Overturn the wall software" or a VPN or something! The LZ side uses a free wall flip software with a good network speed and unlimited traffic, but it is broken every ten minutes. This is a pitfall, but we only need to test it, it is acceptable to be a strong hacker. If you have the conditions, you can buy a VPN.

Http://www.xroute.net/(XROUTE network accelerator) This is its official website, no conditions can be like LZ to use this software to learn.

 

1. download the latest Facebook SDK for Android 3.0: http://developers.facebook.com/android/

2. Download and unzip the facebook-android-sdk-3.0.

Use eclipse to import the project. The FacebookSDK project appears in the facebook folder under the decompressed folder.

3. Create the first Facebook project FirstFacebook and import the FacebookSDK project package

Note: If the imported project package is incorrectly displayed, check whether the FacebookSDK project package and the project you created are in the same directory.

If an error is reported for the project you created after the import is complete, check whether there is a android-support-v4.jar jar file under the libs folder under the project, if so, delete it, and then re-import

FacebookSDK project package. The reason is that this package is also integrated in FacebookSDK, so there will be conflicts.

4, enter the https://developers.facebook.com/facebook developer website, no account to register an account, some directly log on. Click Apps in the navigation bar to enter the application area.

Create a new App clickCreate New AppButton to bring up the following dialog box. The App Name is the Name given to the App. you can skip the following and click Continue.

Click the Native Android App to enter the following data:

Package Name application Package Name

Class Name full Class Name of the application entry Activity

Key Hashes Hash Value

Select enable Facebook Login

Save the changes.

How to obtain the hash value:

Download openssl-0.9.8k_WIN32: After the http://download.csdn.net/detail/h7870181/5054864 is downloaded, unzip it to the C root directory

Enter cmd and paste the following string. The default password for keystore is android. Do not write it wrong. A string of characters is the hash value we need.

 

[Plain]View plaincopyprint?
  1. Keytool-export-alias myAlias-keystore C: \ Users \ Administrator \. android \ debug. keystore | C: \ openssl-0.9.8k_WIN32 \ bin \ openssl sha1-binary | C: \ openssl-0.9.8k_WIN32 \ bin \ openssl enc-a-e

Note that you also need to enter the hash value you just obtained!

OK! The configuration is complete!

 

5. Let's take a look at how the configuration is configured in the project.

Add the network permission in AndroidMainfest. xml and the App Id created in facebook

 

[Html]View plaincopyprint?
  1. <? Xmlversion = "1.0" encoding = "UTF-8"?>
  2. <Manifestxmlns: android = "http://schemas.android.com/apk/res/android"
  3. Package = "com. thirdfacebook"
  4. Android: versionCode = "1"
  5. Android: versionName = "1.0" type = "codeph" text = "/codeph">
  6. <Uses-sdk
  7. Android: minSdkVersion = "8"
  8. Android: targetSdkVersion = "16"/>
  9. <Uses-permissionandroid: name = "android. permission. INTERNET"/>
  10. <Application
  11. Android: allowBackup = "true"
  12. Android: icon = "@ drawable/ic_launcher"
  13. Android: label = "@ string/app_name"
  14. Android: theme = "@ style/AppTheme">
  15. <Activity
  16. Android: name = "com. thirdfacebook. MainActivity"
  17. Android: label = "@ string/app_name">
  18. <Intent-filter>
  19. <Actionandroid: name = "android. intent. action. MAIN"/>
  20. <Categoryandroid: name = "android. intent. category. LAUNCHER"/>
  21. </Intent-filter>
  22. </Activity>
  23. <Meta-dataandroid: name = "com. facebook. sdk. ApplicationId" android: value = "@ string/app_id"/>
  24. </Application>
  25. </Manifest>
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.thirdfacebook"    android:versionCode="1"    android:versionName="1.0" >    <uses-sdk        android:minSdkVersion="8"        android:targetSdkVersion="16" />    <uses-permission android:name="android.permission.INTERNET"/>    <application        android:allowBackup="true"        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >        <activity            android:name="com.thirdfacebook.MainActivity"            android:label="@string/app_name" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>        <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>    </application></manifest>

Add app_id to string. xml

 

 

[Html]View plaincopyprint?
  1. <? Xmlversion = "1.0" encoding = "UTF-8"?>
  2. <Resources>
  3. <Stringname = "app_name"> ThirdFacebook </string>
  4. <Stringname = "hello_world"> Hello world! </String>
  5. <Stringname = "menu_settings"> Settings </string>
  6. & Lt; stringname = "app_id" & gt; 158121714340391 & lt;/string & gt;
  7. </Resources>
<?xml version="1.0" encoding="utf-8"?><resources>    <string name="app_name">ThirdFacebook</string>    <string name="hello_world">Hello world!</string>    <string name="menu_settings">Settings</string>    <string name="app_id">158121714340391</string></resources>

OK! If there is no error in running the project, it indicates that FacebookSDK is successfully integrated. The next article introduces how to log on with Facebook!

 

 

The above is a little bit of your own experience. I will share it with you. If you have any questions, I hope you can tell me!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.