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?
- 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?
- <? Xmlversion = "1.0" encoding = "UTF-8"?>
- <Manifestxmlns: android = "http://schemas.android.com/apk/res/android"
- Package = "com. thirdfacebook"
- Android: versionCode = "1"
- Android: versionName = "1.0" type = "codeph" text = "/codeph">
- <Uses-sdk
- Android: minSdkVersion = "8"
- Android: targetSdkVersion = "16"/>
- <Uses-permissionandroid: 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>
- <Actionandroid: name = "android. intent. action. MAIN"/>
- <Categoryandroid: name = "android. intent. category. LAUNCHER"/>
- </Intent-filter>
- </Activity>
- <Meta-dataandroid: name = "com. facebook. sdk. ApplicationId" android: value = "@ string/app_id"/>
- </Application>
- </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?
- <? Xmlversion = "1.0" encoding = "UTF-8"?>
- <Resources>
- <Stringname = "app_name"> ThirdFacebook </string>
- <Stringname = "hello_world"> Hello world! </String>
- <Stringname = "menu_settings"> Settings </string>
- & Lt; stringname = "app_id" & gt; 158121714340391 & lt;/string & gt;
- </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!