fbas


Facebook Graph API library

http://fbas.googlecode.com/files/icon_128.png

Facebook Graph API

Apr 2010: Facebook introduced their new API, Graph API, which completely replaces the old REST API.

This API has been rewritten to support Graph API.

Downloads: http://code.google.com/p/fbas/downloads/detail?name=fbgraph20100511.zip

SVN: https://fbas.googlecode.com/svn/trunk/fbgraph

What is Graph API

Note: please read this section

Read: You gave it an url in the form of http://graph.facebook.com/{id}/{connection}, Facebook will return a dynamic object representing the data.

Write: You do a http POST to an url

If you chew on this for a little bit, you will see the beauty of the Graph API and the beauty of this library. By calling GraphApi read() or write() method, you have access to the entire Graph API.

Usage

Note: Because our OAuthUtil class uses ExternalInterface, you must set allowScriptAccess="always" or "sameDomain"

~~Note2: Your web page need to be on https because the graph api url are in https~~ (This no longer is the case after Facebook relax the crossdomain.xml a few months back)

First, embed the following javascript code in html. The following javascript code will go through Facebook OAuth mechanism. It will redirect user to Facebook's authentication page, then Facebook will redirect user back after login is done. (If the user is already login, then it should redirect the user right back).

```

// careful! this is for example only. we are using global namespace. var appId = "109401095767649"; // for testing on http://localhost:8888 fbAuthorize(); function fbAuthorize() { // get the hash var hash = self.document.location.hash.substring(1); if (hash.indexOf("access_token") == -1) { var authorizeUrlTemplate = "https://graph.facebook.com/oauth/authorize?client_id=$client_id$&redirect_uri=$redirect_uri$&type=user_agent&display=popup"; var authorizeUrl = authorizeUrlTemplate.replace("$client_id$", appId); authorizeUrl = authorizeUrl.replace("$redirect_uri$", window.location); window.location = authorizeUrl; } else { // access_token exist. we can continue. (log?) } }

```

Flex code:

``` var apiUrl = "http://graph.facebook.com/me/likes"; var graphApi:GraphApi = new GraphApi(); graphApi.read(apiUrl, getFriendsCallback);

```

...

```

private function getFriendsCallback(result:FbCallbackResult):void { if (result.success) {
for each (var likeObj:Object in result.result.data) { var like:Like = new Like(); like.id = likeObj.id; like.name = likeObj.name; like.category = likeObj.category;

                // do something to like object.......
            }
        } else {
             Alert.show(result.faultEvent.fault.faultString);
        }
    } 

```


Below are Legacy Info:

If you are a new user, ignore the old info below.

Facebook made changes to their API, too often for many's likings. So we have to update the API as well.

Downloads: http://code.google.com/p/fbas/downloads/list

Extending Jason Crist's facebook-actionscript-api.

Jason Crist's original api: http://code.google.com/p/facebook-actionscript-api

To access opensocial (such as Myspace, orkut, Hi5, Netlog, Hyve, etc) through actionscript: http://code.google.com/p/opensocial-actionscript-client

Bebo Port

This API library is ported to Bebo. It is not yet in the download section, but you can get the source code from svn (get Facebook.as file). It hasn't been tested much. Only one basic API call is tested for WidgetSession and one API call is tested for DesktopSession. Feel free to let me know or comment if something is broken.

Quick setup

  1. Go to download page to download the latest zip file.
  2. From Flex Builder, import the zip file. After import, it should show up as a Flex project in your Flex Builder workspace.
  3. Your Flex project will need to include this Flex project or include the .swc file generated by this Flex project.

Here are the new API methods added to the original facebook-actionscript-api

  1. Fbml API (Facebook.fbml.xxxxxx)
    1. fbml.refreshImgSrc
    2. fbml.refreshRefUrl
    3. fbml.setRefHandle
  2. Part of datastore API
    1. data.setUserPreference
    2. data.getUserPreference
    3. data.createObjectType
    4. data.createObject
    5. data.updateObject
    6. data.deleteObject
    7. data.getObject
    8. data.getHashValue
    9. data.setHashValue
    10. data.incHashValue
    11. data.removeHashKey
    12. data.removeHashKeys
  3. For some of the API that no longer require session key, remove the session key
  4. New feed API for new facebook profile (one-line-story, short-story, and full-story templates)
    1. feed.deactivateTemplateBundleByIDDelegate
    2. feed.getRegisteredTemplateBundleByID
    3. feed.getRegisteredTemplateBundles
    4. feed.publishUserAction
    5. feed.registerTemplateBundleDelegate

Other changes

  1. notifications.send() and feed.publishTemplatizedActionDelegate() now takes either an array of FacebookUser or an array of uid. These two methods used to take only an array of FacebookUser as argument.
  2. fix bug on feed.publishTemplatizedAction()
  3. fix bug on photos.getTags()

Change logs

2008/08/24

For widgetSession, choose different Facebook API server URL based on whether user is on new or old Facebook. Default to new Facebook.

files changed: Facebook.as

changes r11

2008/08/26

Add new feed APIs for new facebook profile (one-line-story, short-story, and full-story templates). APIs include register, get, deactivate template-bundle, and publisherUserAction.

files added:

data model: * FullStoryTemplate * ShortStoryTemplate * TemplateBundle

delegate: * DeactivateTemplateBundleByIDDelegate * GetRegisteredTemplateBundleByIDDelegate * GetRegisteredTemplateBundlesDelegate * PublishUserActionDelegate * RegisterTemplateBundleDelegate

files modified: * PublishTemplatizedActionDelegate * Feed

changes r13

2008/08/30-31

notifications.send and feed.publishTemplatizedActionDelegate now takes either an array of FacebookUser or an array of uid. These two methods used to take only an array of FacebookUser as argument.

Files modified: SendNotificationsDelegate PublishTemplatizedActionDelegate

changes r16, r18

Backward-compatible: yes

2008/09/01

Fix bug on PublishTemplatizedActionDelegate regarding image_4 parameters. Previously, image_4 parameters is mistyped as image_3

Files modified: PublishTemplatizedActionDelegate.as

change r20

Backward-compatible: yes

2008/10/12 and 10/14

Fix bug on photos.getTags() (GetTagsDelegate) 1. The parameter name should be "pids" instead of "photos" - without this change, getTags() will always return empty 2. handle both user tag and pure-text tag - There are 2 types of tags, user tag (the tag represents a user). pure-text tag (the tag does not represent a Facebook user, it can be any text that is entered).

Files modified: GetTagsDelegate.as

change r26, r27, r25

Backward-compatible: yes

2008/12/10

uid should be Number, not int Facebook uid is 64 bits. Bebo uid is also 64 bits.

Files modified: FacebookUser.as GetSessionDelegate.as

change r28

Backward-compatible: yes

2008/12/16

revert change made in r11. r11 allows app to distinguish between old and new profile and use different api url. Since Facebook has permanently removed old profile. So now api.facebook.com or api.new.facebook.com does the same thing. There is no need to distinguish between old and new facebook profile.

Files modified: Facebook.as

change r29

Backward-compatible: no

2008/12/16

Port this library to Bebo. startWidgetSession() and startDesktopSession() should both work.

Files modified: Facebook.as

change r30

Backward-compatible: yes

2008/12/23, 2009/01/02

uid should be Number, not int. (because Facebook uid can be 64bits)

Files modified: GetAlbumsDelegate.as Photo.as GetFriendsDelegate.as

change r31, r36

Backward-compatible: yes

2009/01/09

create new constants NETWORK_FB and NETWORK_BEBO.

Files modified: Facebook.as

change r37

Backward-compatible: yes

Project Information

Labels:
facebook actionscript api flex as3 bebo graph graphapi