21
PARSING FACEBOOK DATA FOR ANDROID 1

PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step Import Android SDK Get the hash key Create a new app Create a new project in Eclipse

Embed Size (px)

Citation preview

Page 1: PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse

1

PARSING FACEBOOK DATA FOR ANDROID

Page 2: PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse

2

Step by Step

1. Import Android SDK

2. Get the hash key

3. Create a new app

4. Create a new project in Eclipse

5. Setting android layout

6. File Class in Package Folder

7. Edit AndoidManifest.xml

8. Run your app!

Page 3: PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse

3

Import Android SDK

Download Android SDK from https://developers.facebook.com/docs/android

Import SDK to your workspace

Page 4: PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse

4

Get the Hash Key

Download and extract OpenSSL from https://code.google.com/p/openssl-for-windows/downloads/detail?name=openssl-0.9.8k_WIN32.zip

Get the path location of OpenSSL/bin

Get the path location of debug.keystore from android folder

C:\Users\User\.android

Page 5: PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse

5

Get the Hash Key (cont.)

Open cmd

Change root in command line with path location of Java jre. example :

Write this command

Example :

keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | openssl sha1 -binary | openssl base64

keytool -exportcert -alias androiddebugkey -keystore “C:\Users\User\.android\debug.keystore”| “C:\OpenSSL\bin\openssl” sha1 -binary | “C:\OpenSSL\bin\openssl” base64

Path debug.keystore Path openssl.exe

Page 6: PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse

6

Get the Hash Key (cont.)

Will appear hash key in command line. Save the hash key.

Hash key

Page 7: PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse

7

Create a facebook app

Open link facebook developer.

Create a New App.

Page 8: PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse

8

Create a facebook app (cont.)

Save App ID. We will use the ID in androidmanifest.xml (setting for android)

Page 9: PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse

9

Create a facebook app (cont.)

Go to 'Settings' in the left navigation, then click on the 'Add Platform' button, and select Android. Add the debug hash key from previous step.

Change button Single Sign On to “Yes”

Page 10: PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse

10

Create New Project in Eclipse

When you create new android application, dont’ forget to use package name that you have written when create a facebook app (previous step)

Minimum android SDK for facebook API

Page 11: PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse

11

Create New Project in Eclipse (cont.)

Right click at the project, then choose Properties

Go to ‘Android’ in the left nav and add facebook SDK library

Page 12: PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse

12

Create New Project in Eclipse (cont.)

Add tag string app_id from previous step to res/values/string.xml

Page 13: PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse

13

Create New Project in Eclipse (cont.)

Copy all file above to your libs folder.

We use Parse library from www.parse.com to easier access facebook data

Page 14: PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse

14

Setting android layout

Open /res/layout/main.xml. Edit the code

Graphical layout

main.xml

Page 15: PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse

15

Setting android layout (cont.)

Make new userdetails.xml file in res/layout

Graphical layoutuserdetails.xml

Page 16: PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse

16

Setting android layout (cont.)

Page 17: PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse

17

Setting android layout (cont.)

Page 18: PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse

18

File Class in Package Folder

Add new LoginActivity class (you can copy the code but dont forget to change package name in first line of the code)

This activity will call the facebook login and ask permission from the user.

This activity also call parse libraries to parsing data user with JSON.

You can setting the data you will access in list permission. For more information facebook data that allowed to access can you see in https://developers.facebook.com/docs/graph-api/reference/user

Page 19: PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse

19

File Class in Package Folder (cont.)

Add new UserDetailsActivity.java class (you can copy the code but dont forget to change package name in first line of the code)

This class is to show result of parsing data.

Add new IntegratingFacebookTutorialApplication.java class (you can copy the code but dont forget to change package name in first line of the code)

This class will connect Parse Library to your class.

Page 20: PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse

20

Edit AndoidManifest.xml

This application need to connect with internet. So you need to add some permission tag

The activity must initialize in tag application and add meta-data tag

<uses-permission android:name="android.permission.INTERNET"/><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Page 21: PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse

21

Run the application

Now, your application ready to run !