Skip to content

Commit

Permalink
Merge branch 'master' of github.com:facebook/facebook-android-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
Vikas Gupta committed Oct 10, 2011
2 parents da41838 + d5f31b8 commit 2b80bcf
Show file tree
Hide file tree
Showing 52 changed files with 3,988 additions and 52 deletions.
56 changes: 4 additions & 52 deletions README.md
Expand Up @@ -3,68 +3,20 @@ This open source Java library allows you to integrate Facebook into your Android
Getting Started
===============

See our [Android SDK Getting Started Guide](http://developers.facebook.com/docs/guides/mobile#android)
See our [Android SDK Getting Started Guide](https://developers.facebook.com/docs/mobile/android/build/)

Sample Applications
===============

This library includes two sample applications to guide you in development.
This library includes three sample applications to guide you in development.

* __simple__: A bare-bones app that demonstrates authorization, making API calls, and invoking a dialog.

* __stream__: This slightly beefier application lets you view your news feed.

To install a sample application into Eclipse (3.5):
* __Hackbook__: This includes Single Sign On implementation (SSO), sample API calls, and advanced features like Get new Permissions, Run sample FQL Query and Graph API Explorer. Check out [Hackbook for Android](https://developers.facebook.com/docs/mobile/android/hackbook/)

* Create the sample application in your workspace:
2. Select __File__ -> __New__ -> __Project__, choose __Android Project__, and then click __Next__.
3. Select "Create project from existing source".
4. Choose either __examples/simple__ or __examples/stream__. You should see the project properties populated.
5. Click Finish to continue.

* Build the project: from the Project menu, select "Build Project".

* Run the application: from the Run menu, select "Run Configurations...". Under Android Application, you can create a new run configuration: give it a name and select the simple Example project; use the default activity Launch Action. See http://developer.android.com/guide/developing/eclipse-adt.html#RunConfig for more details.


Testing
===============

Here are some tips to help test your application:

* You will need to have the Facebook application in your test environment. The SDK includes a developer release of the Facebook application that can be side-loaded for testing purposes. On an actual device, you can just download the latest version of the app from the Android Market, but on the emulator you will have to install it yourself:

adb install FBAndroid.apk

* Use a signed build. You can sign with a debug key, but make sure that the key you used to sign matches the __Key Hash__ field in the Facebook developer settings.

* Make sure to test both with and without the Facebook application. The SDK will fall back to a Webview if the Facebook app is not installed.

* You can use this [guide to developing on a device](http://developer.android.com/guide/developing/device.html).

Debugging
==========

Here's a few common errors and their solutions.

* __Build error: "missing gen files".__

This should go away when you rebuild the project. If you have trouble, try running __Clean...__ from the __Project__ menu.

* __Error: "invalid_key"__

This error means that the Facebook server doesn't recognize your Android key hash. Make sure that you correctly generated and copy/pasted your key hash into the Facebook developer settings console (http://www.facebook.com/developers/apps.php), and make sure that your application has been signed with the same key you registered with Facebook.

* __Dialog won't load or shows a blank screen.__

This can be tricky to debug. If the logs don't give an indication of what's wrong, I suggest installing tcpdump on your device and getting a trace. Tutorial: http://www.vbsteven.be/blog/android-debugging-inspectin-network-traffic-with-tcpdump/

If you still can't tell what's going on, then file an issue and please include the HTTP trace.

* __I can't upload photos with photos.upload.__

Make sure the Bundle value for the photo parameter is a byte array.

Report Issues/Bugs
===============
[http://bugs.developers.facebook.net/enter_bug.cgi?product=SDKs](http://bugs.developers.facebook.net/enter_bug.cgi?product=SDKs)
[Facebook Stackoverflow](http://facebook.stackoverflow.com/questions/tagged/android)
49 changes: 49 additions & 0 deletions examples/Hackbook/AndroidManifest.xml
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.facebook.android"
android:versionCode="1"
android:versionName="1.0">
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:anyDensity="true" />
<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:debuggable="true">
<activity android:name=".SplashActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Hackbook"
android:label="@string/app_name"
android:configChanges="keyboardHidden"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".GraphExplorer"
android:windowSoftInputMode="stateHidden"
android:screenOrientation="portrait" />
<activity android:name=".IntentUriHandler">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="fbgraphex" />
</intent-filter>
</activity>
<activity
android:name=".FriendsList"
android:screenOrientation="portrait" />
<activity
android:name=".Places"
android:screenOrientation="portrait" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-sdk android:minSdkVersion="3" />
</manifest>
130 changes: 130 additions & 0 deletions examples/Hackbook/README.md
@@ -0,0 +1,130 @@
This 'Hackbook for Android' app includes Single Sign On implementation (SSO), sample API calls and Graph API Explorer and is targeted towards android developers who want to make their apps social using Facebook Social Graph. The Code provided here is to showcase how to implement the SSO and make the API calls. If you have any questiosn or comments related to this sample app, please post them here - http://facebook.stackoverflow.com/questions/tagged/hackbook-for-android

Getting Started
===============

See Android tutorial - https://developers.facebook.com/docs/mobile/android/build/

Configuring the app
===============

1. Launch Eclipse
2. Ensure you have installed the Android plugin.
3. Create Facebook SDK Project - follow the Step-1 instructions in the tutorial
4. Create the Hackbook Project :
4.1 Select __File__ -> __New__ -> __Project__, choose __Android Project__, and then click __Next__.
4.2 Select "Create project from existing source".
4.3. Choose examples/Hackbook. You should see the project properties populated.
4.4. Click Finish to continue.
5. Add reference to the Facebook SDK - follow the Step-3 instructions in the tutorial
6. Create a Facebook app if you don't have one already and add the app id in the Hackbook.java->APP_ID

Build the app
===============

7. And you are done and ready to compile the project:
7.1 From the Project menu, select "Build Project".

Run the app
===============

8. Hopefully project would compile fine. Next run the app on the emulator or on the phone (See http://developer.android.com/guide/developing/eclipse-adt.html#RunConfig for more details.)
8.1 If you plan to run on emulator, ensure you have created an Android Virtual Device (AVD):
8.1.1 Go to Window -> Android SDK and AVD Manager -> Click New
8.1.2 Provide a Name (AVD 2.3 e.g.) and choose the Target (Android 2.3 if available).
8.1.3 Click 'Create AVD' at the bottom and that should create an AVD which you can run the app on described next.

8.2 Go to Run->Run Configurations->Android Application->create a new run configuration by clicking the icon with + button on it.
8.3 Name it 'Hackbook'
8.4 Under the Project, Browse and choose Hackbook
8.5 Go to Target tab -> Choose manual if you wish to run on the phone, else choose Automatic and select an AVD created in step 8.1
8.6 Click Run and your 'Hackbook for Android' app should be up and running.


Installing the Facebook app
===============

You will need to have the Facebook application on the handset or the emulator to test the Single Sign On. The SDK includes a developer release of the Facebook application that can be side-loaded for testing purposes. On an actual device, you can just download the latest version of the app from the Android Market, but on the emulator you will have to install it yourself:

adb install FBAndroid.apk

What's in there
===============

Note: The source tags are provided through out the code base to facilitate easy search for the relevant code. Do a project-wide search for the source tags to get straight to the relevant code. Refer below for source tags for each feature.

1. Login button - This uses SSO to authorize the app. Clicking on Login should activate SSO (if the app is installed) or show OAuth dialog. When authorizing, no permissions are requested and the app will get basic permission by default.

Source Tag - login_tag

- Hackbook.java - this layout the login button and initialize it. Since this is also the calling acitivty, this overrides the onActivityResult() method.
- LoginButton.java - this calls the mFb.authorize(mActivity, mPermissions, mActivityCode, new LoginDialogListener()) which authorizes the app via SSO or OAuth.
- SessionStore.java - stores the access token and access expiry time for future app launch. This is important that you save the access token, else user will need to authorize your app each time they launch it which is annoying and user is likely to churn out.
- SessionEvents.java - Authorization state tracker, calls the listener on login/logout success or error.
------------------------

2. Update Status - this allows user to update his status by calling the 'feed' dialog. More info on feed dialog - https://developers.facebook.com/docs/reference/dialogs/feed/

Source Tag - update_status_tag, view_post_tag, delete_post_tag

- Hackbook.java - Case 0: update status by calling the 'feed' dialog.
- UpdateStatusResultDialog.java - shows the object-id returned in the dialog response. You can view or delete the post here.
------------------------

3. App Requests - this allows to send app requests to user's friends by calling the 'apprequests' dialog. More info - https://developers.facebook.com/docs/reference/dialogs/requests/

Source Tag - app_requests_tag

- Hackbook.java - Case 1: send the app requests by calling the the 'apprequests' dialog.
------------------------

4. Get Friends - Get user's friends via Graph API or FQL Query. User must be logged-in to use this. Also post on a friend's wall by clicking on his name in the list.

Source Tag - get_friends_tag, friend_wall_tag

- Hackbook.java - Case 2: Use Graph API 'me/friends' which returns friends sorted by UID, currently it's not possible to sort any other way in the Graph API. Use the FQL Query to sort by name - select name, current_location, uid, pic_square from user where uid in (select uid2 from friend where uid1=me()) order by name
- FriendsList.java - displays the friends profile pic and names as returned by the api. Also post on friend's wall by clicking on the friend.
- FriendsModel.java - run async tasks to fetch the profile picture limited to 15 tasks at any given time.

5. Upload Photo - Upload a photo either from the media gallery or from a remote server. You require 'photo_upload' to upload photos on user profile.

Source Tag - upload_photo, view_photo_tag, tag_photo_tag

- Hackbook.java - Case 3: Photo is uploaded by posting byte-array or url to me/photos endpoint. Media Gallery is launched by invoking the MediaStore.Images.Media.EXTERNAL_CONTENT_URI intent and overriding the OnActivityResult() to get the picture from the media gallery. Photo from remote server is uploaded by simply providing the image url in the 'url' param in the graph.facebook.com/me/photos endpoint.
- UploadPhotoResultDialog.java - shows the object-id returned after uploaded the photo. You can view or tag the photo here.
------------------------


6. Place Check-in - Fetch user's current location or use Times Square as the current location and get nearby places which user can check-in at.

Source Tag - fetch_places_tag, check_in_tag

- Hackbook.java - Case 4: Ask to fetch current location or use Times Square as the current location.
- Places.java - Get user's current location and fetch the nearby places by calling the graph.facebook.com/search?type=places&distance=1000&center=lat,lon. Check-in user at a place by calling the graph.facebook.com/me/checkins&place=<place_id_>&message=<message>&coordinates={"latitude": <lat>, "longitude:": <lon>}
------------------------

7. Run FQL Query - Type and run any FQL Query and see the results.

Source Tag - fql_query_tag

- FQLQuery.java - Layout the FQL Query Dialog and run the query and show the results.
------------------------

8. Graph API Explorer - Explore user's social graph, see his and friends' connections and get new permissions. This is similar to the Graph Explorer dev tool - http://developers.facebook.com/tools/explorer/. The ObjectIDs in the API response are linkified and can be clicked to fetch object specific data.
- Click the 'x' button to clear the textfield
- Click the green up arrow button in the textfield to get the 'me' object data.
- Click on 'Get Permissions' to get new permissions including user's, his friends or extended permissions.
- Click on 'Fields/Connections' to see current object's fields and connections.
- On the Fields & Connections dialog, in the Fields tab, select the fields to view or in the Connections tab, click the connection to view it's content.

Source Tag - graph_explorer

- Hackbook.java - Case 5: Launch the GraphExplorer intent
- GraphExplorer.java - Layout and execute the graph explorer
- IntentUriHandler.java - Handle the fbgraphex: schema generated while linkifying the Object IDs in the graph explorer output



Report Issues/Bugs
===============
Please report issues here - http://facebook.stackoverflow.com/questions/tagged/hackbook-for-android
14 changes: 14 additions & 0 deletions examples/Hackbook/default.properties
@@ -0,0 +1,14 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.

# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
target=android-8
android.library.reference.1=../../../newdialog/facebook-android-sdk/facebook
Binary file added examples/Hackbook/res/drawable-hdpi/splash.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/Hackbook/res/drawable/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/Hackbook/res/drawable/icon_hack.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/Hackbook/res/drawable/login.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions examples/Hackbook/res/drawable/login_button.xml
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/login_down" />
<item android:drawable="@drawable/login" /> <!-- default -->
</selector>
Binary file added examples/Hackbook/res/drawable/login_down.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/Hackbook/res/drawable/logout.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions examples/Hackbook/res/drawable/logout_button.xml
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/logout_down" />
<item android:drawable="@drawable/logout" /> <!-- default -->
</selector>
Binary file added examples/Hackbook/res/drawable/logout_down.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/Hackbook/res/drawable/me.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/Hackbook/res/drawable/splash.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/Hackbook/res/drawable/x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions examples/Hackbook/res/layout/connection_item.xml
@@ -0,0 +1,11 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight">
<TextView
android:id="@+id/connection_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="26sp"
android:textColor="@color/lite_blue"
android:paddingLeft="5dp" />
</RelativeLayout>
45 changes: 45 additions & 0 deletions examples/Hackbook/res/layout/fields_connections_list.xml
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/black">
<TabHost
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/tabHost">
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<TabWidget
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@android:id/tabs" />
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@android:id/tabcontent"
android:layout_below="@android:id/tabs">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/fields_layout">
<Button android:id="@+id/get_fields_button"
android:text="@string/get_fields"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp" />
<ListView
android:id="@+id/fields_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<ListView
android:id="@+id/connections_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
</RelativeLayout>
</TabHost>
</LinearLayout>
14 changes: 14 additions & 0 deletions examples/Hackbook/res/layout/fields_item.xml
@@ -0,0 +1,14 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/black">
<CheckBox
android:id="@+id/fields_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/fields_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

0 comments on commit 2b80bcf

Please sign in to comment.