Class FaceBookAccess

java.lang.Object
com.codename1.facebook.FaceBookAccess

public final class FaceBookAccess extends Object
This is the main access API to the facebook graph API http://developers.facebook.com/docs/reference/api/ This class encapsulates the Network access and provide simple methods to acess the Facebook servers.
  • Method Details

    • getInstance

      public static FaceBookAccess getInstance()

      gets the class instance

      Returns

      a FaceBookAccess object

    • createObjectsModel

      public static DefaultListModel createObjectsModel(DefaultListModel hashtablesModel, Class fbObjectClass) throws IllegalAccessException, InstantiationException

      This is a utility method that transforms a DefaultListModel that contains Hashtable entries into a DefaultListModel that will contain FBObject objects that will be initialized with the Hashtable entries

      Parameters
      • hashtablesModel: the model to transform, this model should hold it's data has Hashtable entries

      • fbObjectClass: this is the class of the entries to be created, this class should be a FBObject type

      Returns

      a DefaultListModel with fbObjectClass objects entries

      Throws
      • IllegalAccessException: if the fbObjectClass.newInstance() fails

      • InstantiationExceptionif: the fbObjectClass.newInstance() fails

      Throws:
      IllegalAccessException
      InstantiationException
    • setClientId

      public static void setClientId(String clientId)

      The client id (appid) which asks to connect (this is generated when an app is created see: https://developers.facebook.com/apps)

      Parameters
      • clientId
    • setClientSecret

      public static void setClientSecret(String clientSecret)

      The client secret is been generated by facebook see: https://developers.facebook.com/apps

      Parameters
      • clientSecret
    • setPermissions

      public static void setPermissions(String[] permissions)

      The requested permissions of the app http://developers.facebook.com/docs/reference/api/permissions/

      Parameters
      • permissions
    • setRedirectURI

      public static void setRedirectURI(String redirectURI)

      This is generated when an app is created see: https://developers.facebook.com/apps

      Parameters
      • redirectURI
    • getToken

      public static String getToken()

      Returns the Facebook authorization token that can be used for API access

      Returns

      the token

    • setToken

      public static void setToken(String tok)

      Sets the token to the FaceBookAccess class, this is useful if the token has not yet expired, get the expiration of the token with Oauth2.getExpires()

      Parameters
      • tok: the token of the
    • logOut

      public static void logOut()
      log out the current user
    • anonymousLogin

      public static void anonymousLogin(String appid, String clientSecret)

      Some simple queries for public data can work just fine with anonymous login without requiring the whole OAuth process, they still need a facebook application though

      Parameters
      • appid: the id of the application

      • clientSecret: the client secret for the application

    • getApiVersion

      public static String getApiVersion()
      Returns the api version used, if empty the non version-ed is used
    • setApiVersion

      public static void setApiVersion(String apiVersion)

      Sets the Facebook api version being used, by default the api calls the non version-ed version of the API.

      Parameters
      • apiVersion: valid values are "1.0", "2.0", "2.1"
    • createOAuth

      public Oauth2 createOAuth()
    • createAuthComponent

      public Component createAuthComponent(ActionListener<ActionEvent> al)

      This method creates a component which can authenticate. You will receive either the authentication key or an Exception object within the ActionListener callback method.

      Parameters
      • al: a listener that will receive at its source either a token for the service or an exception in case of a failure
      Returns

      a component that should be displayed to the user in order to perform the authentication

    • showAuthentication

      public void showAuthentication(ActionListener<ActionEvent> al)

      This method shows an authentication for login form

      Parameters
      • al: @param al a listener that will receive at its source either a token for the service or an exception in case of a failure
    • isAuthenticated

      public boolean isAuthenticated()

      This method returns true if the user is authenticated to the facebook service.

      Returns

      true if authenticated

    • setProgress

      public void setProgress(Slider slider)

      Sets the progress indicator to get network updates on the queries

      Parameters
      • slider
    • getFaceBookObject

      public void getFaceBookObject(String faceBookId, ActionListener<NetworkEvent> callback) throws IOException

      This method returns immediately and will call the callback when it returns with the FaceBook Object data.

      Parameters
      • faceBookId: the object id that we would like to query

      • callback: the callback that should be updated when the data arrives

      Throws:
      IOException
    • getFaceBookObject

      public void getFaceBookObject(String faceBookId, ActionListener<NetworkEvent> callback, boolean needToken, boolean async) throws IOException

      This method returns immediately and will call the callback when it returns with the FaceBook Object data.

      Parameters
      • faceBookId: the object id that we would like to query

      • callback: the callback that should be updated when the data arrives

      • needToken: if true authentication is being checked

      Throws:
      IOException
    • getFaceBookObjectItems

      public void getFaceBookObjectItems(String faceBookId, String itemsConnection, DefaultListModel feed, Hashtable params, ActionListener callback) throws IOException

      Get a list of FaceBook objects for a given id

      Parameters
      • faceBookId: the id to preform the query upon

      • itemsConnection: the type of the query

      • feed

      • params

      • callback: the callback that should be updated when the data arrives

      Throws:
      IOException
    • getUser

      public void getUser(String userId, User user, ActionListener<NetworkEvent> callback) throws IOException

      Gets a user from a user id

      Parameters
      • userId: the user id or null to get detaild on the authenticated user

      • user: an object to fill with the user details

      • callback: the callback that should be updated when the data arrives

      Throws:
      IOException
    • getUser

      public User getUser(String userId) throws IOException

      Gets a User from a user id This is a sync method it will block until a response it returned

      Parameters
      • userId: the user id or null to get details on the authenticated user
      Returns

      the User requested

      Throws:
      IOException
    • getPage

      public Page getPage(String pageId) throws IOException

      Gets a Page from a pageId/name This is a sync method it will block until a response it returned

      Parameters
      • pageId: the pageId
      Returns

      the Page requested

      Throws:
      IOException
    • getPost

      public void getPost(String postId, Post post, ActionListener<NetworkEvent> callback) throws IOException

      Gest a post from a post Id

      Parameters
      • postId: the postId

      • post: an Object to fill with the data

      • callback: the callback that should be updated when the data arrives

      Throws:
      IOException
    • getPost

      public Post getPost(String postId, boolean needAuth) throws IOException

      Gets a Post from a postId This is a sync method it will block until a response it returned

      Parameters
      • postId: the post id

      • needAuth: @param needAuth if this object is public needAuth can be false and no authentication will be performed

      Returns

      the Post requested

      Throws:
      IOException
    • getPhoto

      public void getPhoto(String photoId, Photo photo, ActionListener<NetworkEvent> callback) throws IOException

      Gest a photo from a photo Id

      Parameters
      • photoId: the photoId

      • photo: an Object to fill with the data

      • callback: the callback that should be updated when the data arrives

      Throws:
      IOException
    • getPhoto

      public Photo getPhoto(String photoId, boolean needAuth) throws IOException

      Gets a Photo from a photoId This is a sync method it will block until a response it returned

      Parameters
      • photoId: the photoId

      • needAuth: @param needAuth if this object is public needAuth can be false and no authentication will be performed

      Returns

      the Photo requested

      Throws:
      IOException
    • getAlbum

      public void getAlbum(String albumId, Album album, ActionListener<NetworkEvent> callback) throws IOException

      Gest an album from an albumId

      Parameters
      • albumId: the albumId

      • album: an Object to fill with the data

      • callback: the callback that should be updated when the data arrives

      Throws:
      IOException
    • getAlbum

      public Album getAlbum(String albumId, boolean needAuth) throws IOException

      Gets a Album from a albumId This is a sync method it will block until a response it returned

      Parameters
      • albumId: the albumId

      • needAuth: @param needAuth if this object is public needAuth can be false and no authentication will be performed

      Returns

      the Album requested

      Throws:
      IOException
    • getNewsFeed

      public void getNewsFeed(String userId, DefaultListModel feed, ActionListener callback) throws IOException

      Gets the user news feed, the data is being stored in the given DefaultListModel. By default this method will return last 13 news entries.

      Parameters
      • userId: the userid we would like to query

      • feed: the response to fill

      • callback: the callback that should be updated when the data arrives

      Throws:
      IOException
    • getNewsFeed

      public void getNewsFeed(String userId, DefaultListModel feed, int limit, ActionListener callback) throws IOException

      Gets the user news feed, the data is being stored in the given DefaultListModel.

      Parameters
      • userId: the userid we would like to query

      • feed: the response to fill

      • limit: the number of items to return

      • callback: the callback that should be updated when the data arrives

      Throws:
      IOException
    • getWallFeed

      public void getWallFeed(String userId, DefaultListModel feed, ActionListener callback) throws IOException

      Gets the user wall feed, the data is being stored in the given DefaultListModel. By default this method will return last 13 news entries.

      Parameters
      • userId: the userid we would like to query

      • feed: the response fo fill

      • callback: the callback that should be updated when the data arrives

      Throws:
      IOException
    • getWallFeed

      public void getWallFeed(String userId, DefaultListModel feed, int limit, ActionListener callback) throws IOException

      Gets the user wall feed, the data is being stored in the given DefaultListModel.

      Parameters
      • userId: the userid we would like to query

      • feed: the response to fill

      • limit: the number of items to return

      • callback: the callback that should be updated when the data arrives

      Throws:
      IOException
    • getWallPosts

      public void getWallPosts(String userId, DefaultListModel feed, ActionListener callback) throws IOException

      Gets the user wall feed, the data is being stored in the given DefaultListModel. By default this method will return last 13 news entries.

      Parameters
      • userId: the userid we would like to query

      • feed: the response fo fill

      • callback: the callback that should be updated when the data arrives

      Throws:
      IOException
    • getWallPosts

      public void getWallPosts(String userId, DefaultListModel feed, int limit, ActionListener callback) throws IOException

      Gets the user wall posts, the data is being stored in the given DefaultListModel.

      Parameters
      • userId: the userid we would like to query

      • feed: the response to fill

      • limit: the number of items to return

      • callback: the callback that should be updated when the data arrives

      Throws:
      IOException
    • getPicture

      public void getPicture(String id, Label label, Dimension toScale, boolean tempStorage) throws IOException

      Gets the picture of the given facebook object id

      Parameters
      • id: the object id to query

      • label: place the image on the given label as an icon

      • toScale: scale the image to the given dimension

      • tempStorage: if true place the image in a temp storage

      Throws:
      IOException
    • getPicture

      public void getPicture(String id, ActionListener callback, Dimension toScale, boolean tempStorage) throws IOException

      Gets the picture of the given facebook object id

      Parameters
      • id: the object id to query

      • callback: the callback that should be updated when the data arrives

      • toScale: picture dimension or null

      • tempStorage: if true place the image in a temp storage

      Throws:
      IOException
    • getPictureAndWait

      public EncodedImage getPictureAndWait(String id, Dimension toScale)

      Gets the picture of the given facebook object id

      Parameters
      • id: the object id to query

      • toScale: picture dimension or null

      Returns

      the picture

    • getImageURL

      public String getImageURL(String id, Dimension toScale)

      Returns the URL for a given image

      Parameters
      • id: the id of the image

      • toScale: the resolution we want

      Returns

      a link that should fetch that image

    • getPicture

      public void getPicture(String id, Component targetList, int targetOffset, String targetKey, Dimension toScale, boolean tempStorage) throws IOException

      Gets the picture of the given facebook object id and stores it in the given List in the offset index

      This assumes the GenericListCellRenderer style of list which relies on a hashtable based model approach.

      Parameters
      • id: the object id to query

      • targetList: the list that should be updated when the data arrives

      • targetOffset: the offset within the list to insert the image

      • targetKey: the key for the hashtable in the target offset

      • toScale: the scale of the image to put in the List or null

      • tempStorage: if true place the image in a temp storage

      Throws:
      IOException
    • getPhotoThumbnail

      public void getPhotoThumbnail(String photoId, ActionListener callback, boolean tempStorage) throws IOException

      Gets the photo thumbnail of a Photo Object

      Parameters
      • photoId: the photo id

      • callback: the callback that should be updated when the data arrives

      • tempStorage: if true place the image in a temp storage

      Throws:
      IOException
    • getPhotoThumbnail

      public void getPhotoThumbnail(String photoId, Label label, Dimension toScale, boolean tempStorage) throws IOException

      Gets the photo thumbnail of a Photo Object

      Parameters
      • photoId: the photo id

      • label: place the image on the given label as an icon

      • toScale: scale the image to the given dimension

      • tempStorage: if true place the image in a temp storage

      Throws:
      IOException
    • getUserFriends

      public void getUserFriends(String userId, DefaultListModel friends, ActionListener callback) throws IOException

      Gets the user friends

      Parameters
      • userId: the id

      • friends: @param friends store friends results into the given model, each entry is an Hashtable Object contaning the Object data

      • callback: the callback that should be updated when the data arrives

      Throws:
      IOException
    • getUserAlbums

      public void getUserAlbums(String userId, DefaultListModel albums, ActionListener callback) throws IOException

      Gets the user albums

      Parameters
      • userId: the id

      • albums: @param albums store albums results into the given model, each entry is an Hashtable Object contaning the Object data

      • callback: the callback that should be updated when the data arrives

      Throws:
      IOException
    • getAlbumPhotos

      public void getAlbumPhotos(String albumId, DefaultListModel photos, int offset, int limit, ActionListener callback) throws IOException

      Gets the albums photos

      Parameters
      • albumId: the id

      • photos: @param photos store photos results into the given model, each entry is an Hashtable Object contaning the Object data

      • offset: the offset of the photo in the album

      • limit: amount of photos to bring

      • callback: the callback that should be updated when the data arrives

      Throws:
      IOException
    • getPostComments

      public void getPostComments(String postId, DefaultListModel comments, ActionListener callback) throws IOException

      Gets the post comments

      Parameters
      • postId: the id

      • comments: @param comments store comments results into the given model, each entry is an Hashtable Object contaning the Object data

      • callback: the callback that should be updated when the data arrives

      Throws:
      IOException
    • getUserInboxThreads

      public void getUserInboxThreads(String userId, DefaultListModel threads, int limit, ActionListener callback) throws IOException

      Gets the user inbox Threads

      Parameters
      • userId: the id

      • threads: @param threads store threads results into the given model, each entry is an Hashtable Object contaning the Object data

      • limit: the amount of thread to return

      • callback: the callback that should be updated when the data arrives

      Throws:
      IOException
    • postOnWall

      public void postOnWall(String userId, String message) throws IOException

      Post a message on the users wall

      Parameters
      • userId: the userId

      • message: the message to post

      Throws:
      IOException
    • postLike

      public void postLike(String postId) throws IOException

      Post like on a given post

      Parameters
      • postId: the post Id
      Throws:
      IOException
    • postComment

      public void postComment(String postId, String message) throws IOException

      Post a comment on a given post

      Parameters
      • postId: the post id

      • message: the message to post

      Throws:
      IOException
    • createNote

      public void createNote(String userId, String subject, String message) throws IOException

      Post a note onto the users wall

      Parameters
      • userId: the userId

      • message: the message to post

      Throws:
      IOException
    • postOnWall

      public void postOnWall(String userId, String message, ActionListener callback) throws IOException

      Post a message on the users wall

      Parameters
      • userId: the userId

      • message: the message to post

      Throws:
      IOException
    • postOnWall

      public void postOnWall(String userId, String message, String name, String link, String description, String picture, String caption, ActionListener callback) throws IOException

      Post a message on the users wall

      Parameters
      • userId: the userId

      • message: the message to post

      • name

      • link

      • description

      • picture

      • caption

      Throws:
      IOException
    • postLike

      public void postLike(String postId, ActionListener callback) throws IOException

      Post like on a given post

      Parameters
      • postId: the post Id
      Throws:
      IOException
    • postComment

      public void postComment(String postId, String message, ActionListener callback) throws IOException

      Post a comment on a given post

      Parameters
      • postId: the post id

      • message: the message to post

      Throws:
      IOException
    • createNote

      public void createNote(String userId, String subject, String message, ActionListener callback) throws IOException

      Post a note onto the users wall

      Parameters
      • userId: the userId

      • message: the message to post

      Throws:
      IOException
    • getUserNotifications

      public void getUserNotifications(String userId, String startTime, boolean includeRead, DefaultListModel notifications, ActionListener<NetworkEvent> callback) throws IOException

      Gets the user notifications (this method uses the legacy rest api see http://developers.facebook.com/docs/reference/rest/)

      Parameters
      • userId: the user id

      • startTime: @param startTime Indicates the earliest time to return a notification. This equates to the updated_time field in the notification FQL table. If not specified, this call returns all available notifications.

      • includeRead: @param includeRead Indicates whether to include notifications that have already been read. By default, notifications a user has read are not included.

      • notifications: @param notifications store notifications results into the given model, each entry is an Hashtable Object contaning the Object data

      • callback: the callback that should be updated when the data arrives

      Throws:
      IOException
    • getUsersDetails

      public void getUsersDetails(String[] usersIds, String[] fields, ActionListener<NetworkEvent> callback) throws IOException

      Gets users requested details ((this method uses the legacy rest api see http://developers.facebook.com/docs/reference/rest/))

      Parameters
      • usersIds: the users to query

      • fields: which fields to query on the users see http://developers.facebook.com/docs/reference/rest/users.getInfo/

      • callback: @param callback the result will call the callback with the result to extrct the data preform the following: public void actionPerformed(ActionEvent evt) { Vector data = (Vector) ((NetworkEvent) evt).getMetaData(); Vector users = (Vector) data.elementAt(0); }

      Throws:
      IOException
    • getUserEvents

      public void getUserEvents(String userId, DefaultListModel events, ActionListener callback) throws IOException

      Gets the user events

      Parameters
      • userId: the user id

      • events: @param events store events results into the given model, each entry is an Hashtable Object contaning the Object data

      • callback: the callback that should be updated when the data arrives

      Throws:
      IOException
    • search

      public void search(String objectType, String query, DefaultListModel results, ActionListener callback) throws IOException

      Serach for facebook objects

      Parameters
      • objectType: one of each: post, user, page, event, group, place, checkin

      • query: the query string to search for

      • results: @param results store results onto the given model, each entry is an Hashtable Object contaning the Object data

      • callback: the callback that should be updated when the data arrives

      Throws:
      IOException
    • killCurrentRequest

      public void killCurrentRequest()
      Kills the current request.
    • addResponseCodeListener

      public void addResponseCodeListener(ActionListener a)

      Adds a response listener on the requests

      Parameters
      • a: response listener
    • removeResponseCodeListener

      public void removeResponseCodeListener(ActionListener a)
      Removes a response listener
    • cleanTempStorage

      public void cleanTempStorage()
      Deletes all temp storage.