public final class FaceBookAccess
- Object
- FaceBookAccess
Deprecated. This legacy OAuth2/Graph REST wrapper predates Facebook’s current policies and
embeds credentials client-side, which Facebook no longer permits for production use. Use
FacebookConnect (native SDK path) for login, and a server-side
component for any Graph API access that requires a client secret. This class will be removed
in a future release.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.
Methods
Inherited methods
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, InstantiationExceptionThis 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
hashtablesModelDefaultListModel- the model to transform, this model should hold it’s data has Hashtable entries
fbObjectClassClass- 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
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)
setClientSecret
public static void setClientSecret(String clientSecret)The client secret is been generated by facebook
see: https://developers.facebook.com/apps
setPermissions
public static void setPermissions(String[] permissions)The requested permissions of the app
http://developers.facebook.com/docs/reference/api/permissions/
setRedirectURI
public static void setRedirectURI(String redirectURI)This is generated when an app is created see:
https://developers.facebook.com/apps
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
tokString- 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
appidString- the id of the application
clientSecretString- 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
apiVersionString- 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
alActionListener<ActionEvent>- 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
alActionListener<ActionEvent>- 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
getFaceBookObject
public void getFaceBookObject(String faceBookId, ActionListener<NetworkEvent> callback)
throws IOExceptionThis method returns immediately and will call the callback when it returns with
the FaceBook Object data.
Parameters
faceBookIdString- the object id that we would like to query
callbackActionListener<NetworkEvent>- the callback that should be updated when the data arrives
Throws
getFaceBookObject
public void getFaceBookObject(String faceBookId, ActionListener<NetworkEvent> callback, boolean needToken, boolean async)
throws IOExceptionThis method returns immediately and will call the callback when it returns with
the FaceBook Object data.
Parameters
faceBookIdString- the object id that we would like to query
callbackActionListener<NetworkEvent>- the callback that should be updated when the data arrives
needTokenboolean- if true authentication is being checked
asyncboolean- Not documented.
Throws
getFaceBookObjectItems
public void getFaceBookObjectItems(String faceBookId, String itemsConnection, DefaultListModel feed, Hashtable params, ActionListener callback)
throws IOExceptionGet a list of FaceBook objects for a given id
Parameters
faceBookIdString- the id to preform the query upon
itemsConnectionString- the type of the query
feedDefaultListModel- Not documented.
paramsHashtable- Not documented.
callbackActionListener- the callback that should be updated when the data arrives
Throws
getUser
public void getUser(String userId, User user, ActionListener<NetworkEvent> callback)
throws IOExceptionGets a user from a user id
Parameters
userIdString- the user id or null to get detaild on the authenticated user
userUser- an object to fill with the user details
callbackActionListener<NetworkEvent>- the callback that should be updated when the data arrives
Throws
getUser
public User getUser(String userId)
throws IOExceptionGets a User from a user id
This is a sync method it will block until a response it returned
Parameters
userIdString- the user id or null to get details on the authenticated user
Returns
the User requested
Throws
getPage
public Page getPage(String pageId)
throws IOExceptionGets a Page from a pageId/name
This is a sync method it will block until a response it returned
Parameters
pageIdString- the pageId
Returns
the Page requested
Throws
getPost
public void getPost(String postId, Post post, ActionListener<NetworkEvent> callback)
throws IOExceptionGest a post from a post Id
Parameters
postIdString- the postId
postPost- an Object to fill with the data
callbackActionListener<NetworkEvent>- the callback that should be updated when the data arrives
Throws
getPost
public Post getPost(String postId, boolean needAuth)
throws IOExceptionGets a Post from a postId
This is a sync method it will block until a response it returned
Parameters
postIdString- the post id
needAuthboolean- if this object is public needAuth can be false and no authentication will be performed
Returns
the Post requested
Throws
getPhoto
public void getPhoto(String photoId, Photo photo, ActionListener<NetworkEvent> callback)
throws IOExceptionGest a photo from a photo Id
Parameters
photoIdString- the photoId
photoPhoto- an Object to fill with the data
callbackActionListener<NetworkEvent>- the callback that should be updated when the data arrives
Throws
getPhoto
public Photo getPhoto(String photoId, boolean needAuth)
throws IOExceptionGets a Photo from a photoId
This is a sync method it will block until a response it returned
Parameters
photoIdString- the photoId
needAuthboolean- if this object is public needAuth can be false and no authentication will be performed
Returns
the Photo requested
Throws
getAlbum
public void getAlbum(String albumId, Album album, ActionListener<NetworkEvent> callback)
throws IOExceptionGest an album from an albumId
Parameters
albumIdString- the albumId
albumAlbum- an Object to fill with the data
callbackActionListener<NetworkEvent>- the callback that should be updated when the data arrives
Throws
getAlbum
public Album getAlbum(String albumId, boolean needAuth)
throws IOExceptionGets a Album from a albumId
This is a sync method it will block until a response it returned
Parameters
albumIdString- the albumId
needAuthboolean- if this object is public needAuth can be false and no authentication will be performed
Returns
the Album requested
Throws
getNewsFeed
public void getNewsFeed(String userId, DefaultListModel feed, ActionListener callback)
throws IOExceptionGets the user news feed, the data is being stored in the given DefaultListModel.
By default this method will return last 13 news entries.
Parameters
userIdString- the userid we would like to query
feedDefaultListModel- the response to fill
callbackActionListener- the callback that should be updated when the data arrives
Throws
getNewsFeed
public void getNewsFeed(String userId, DefaultListModel feed, int limit, ActionListener callback)
throws IOExceptionGets the user news feed, the data is being stored in the given DefaultListModel.
Parameters
userIdString- the userid we would like to query
feedDefaultListModel- the response to fill
limitint- the number of items to return
callbackActionListener- the callback that should be updated when the data arrives
Throws
getWallFeed
public void getWallFeed(String userId, DefaultListModel feed, ActionListener callback)
throws IOExceptionGets the user wall feed, the data is being stored in the given DefaultListModel.
By default this method will return last 13 news entries.
Parameters
userIdString- the userid we would like to query
feedDefaultListModel- the response fo fill
callbackActionListener- the callback that should be updated when the data arrives
Throws
getWallFeed
public void getWallFeed(String userId, DefaultListModel feed, int limit, ActionListener callback)
throws IOExceptionGets the user wall feed, the data is being stored in the given DefaultListModel.
Parameters
userIdString- the userid we would like to query
feedDefaultListModel- the response to fill
limitint- the number of items to return
callbackActionListener- the callback that should be updated when the data arrives
Throws
getWallPosts
public void getWallPosts(String userId, DefaultListModel feed, ActionListener callback)
throws IOExceptionGets the user wall feed, the data is being stored in the given DefaultListModel.
By default this method will return last 13 news entries.
Parameters
userIdString- the userid we would like to query
feedDefaultListModel- the response fo fill
callbackActionListener- the callback that should be updated when the data arrives
Throws
getWallPosts
public void getWallPosts(String userId, DefaultListModel feed, int limit, ActionListener callback)
throws IOExceptionGets the user wall posts, the data is being stored in the given DefaultListModel.
Parameters
userIdString- the userid we would like to query
feedDefaultListModel- the response to fill
limitint- the number of items to return
callbackActionListener- the callback that should be updated when the data arrives
Throws
getPicture
public void getPicture(String id, Label label, Dimension toScale, boolean tempStorage)
throws IOExceptionGets the picture of the given facebook object id
Parameters
idString- the object id to query
labelLabel- place the image on the given label as an icon
toScaleDimension- scale the image to the given dimension
tempStorageboolean- if true place the image in a temp storage
Throws
getPicture
public void getPicture(String id, ActionListener callback, Dimension toScale, boolean tempStorage)
throws IOExceptionGets the picture of the given facebook object id
Parameters
idString- the object id to query
callbackActionListener- the callback that should be updated when the data arrives
toScaleDimension- picture dimension or null
tempStorageboolean- if true place the image in a temp storage
Throws
getPictureAndWait
public EncodedImage getPictureAndWait(String id, Dimension toScale)Gets the picture of the given facebook object id
Parameters
idString- the object id to query
toScaleDimension- picture dimension or null
Returns
the picture
getImageURL
public String getImageURL(String id, Dimension toScale)Returns the URL for a given image
Parameters
idString- the id of the image
toScaleDimension- 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 IOExceptionGets 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
idString- the object id to query
targetListComponent- the list that should be updated when the data arrives
targetOffsetint- the offset within the list to insert the image
targetKeyString- the key for the hashtable in the target offset
toScaleDimension- the scale of the image to put in the List or null
tempStorageboolean- if true place the image in a temp storage
Throws
getPhotoThumbnail
public void getPhotoThumbnail(String photoId, ActionListener callback, boolean tempStorage)
throws IOExceptionGets the photo thumbnail of a Photo Object
Parameters
photoIdString- the photo id
callbackActionListener- the callback that should be updated when the data arrives
tempStorageboolean- if true place the image in a temp storage
Throws
getPhotoThumbnail
public void getPhotoThumbnail(String photoId, Label label, Dimension toScale, boolean tempStorage)
throws IOExceptionGets the photo thumbnail of a Photo Object
Parameters
photoIdString- the photo id
labelLabel- place the image on the given label as an icon
toScaleDimension- scale the image to the given dimension
tempStorageboolean- if true place the image in a temp storage
Throws
getUserFriends
public void getUserFriends(String userId, DefaultListModel friends, ActionListener callback)
throws IOExceptionGets the user friends
Parameters
userIdString- the id
friendsDefaultListModel- store friends results into the given model, each entry is an Hashtable Object contaning the Object data
callbackActionListener- the callback that should be updated when the data arrives
Throws
getUserAlbums
public void getUserAlbums(String userId, DefaultListModel albums, ActionListener callback)
throws IOExceptionGets the user albums
Parameters
userIdString- the id
albumsDefaultListModel- store albums results into the given model, each entry is an Hashtable Object contaning the Object data
callbackActionListener- the callback that should be updated when the data arrives
Throws
getAlbumPhotos
public void getAlbumPhotos(String albumId, DefaultListModel photos, int offset, int limit, ActionListener callback)
throws IOExceptionGets the albums photos
Parameters
albumIdString- the id
photosDefaultListModel- store photos results into the given model, each entry is an Hashtable Object contaning the Object data
offsetint- the offset of the photo in the album
limitint- amount of photos to bring
callbackActionListener- the callback that should be updated when the data arrives
Throws
getPostComments
public void getPostComments(String postId, DefaultListModel comments, ActionListener callback)
throws IOExceptionGets the post comments
Parameters
postIdString- the id
commentsDefaultListModel- store comments results into the given model, each entry is an Hashtable Object contaning the Object data
callbackActionListener- the callback that should be updated when the data arrives
Throws
getUserInboxThreads
public void getUserInboxThreads(String userId, DefaultListModel threads, int limit, ActionListener callback)
throws IOExceptionGets the user inbox Threads
Parameters
userIdString- the id
threadsDefaultListModel- store threads results into the given model, each entry is an Hashtable Object contaning the Object data
limitint- the amount of thread to return
callbackActionListener- the callback that should be updated when the data arrives
Throws
postOnWall
public void postOnWall(String userId, String message)
throws IOExceptionPost a message on the users wall
Parameters
userIdString- the userId
messageString- the message to post
Throws
postLike
public void postLike(String postId)
throws IOExceptionPost like on a given post
Parameters
postIdString- the post Id
Throws
postComment
public void postComment(String postId, String message)
throws IOExceptionPost a comment on a given post
Parameters
postIdString- the post id
messageString- the message to post
Throws
createNote
public void createNote(String userId, String subject, String message)
throws IOExceptionPost a note onto the users wall
Parameters
userIdString- the userId
subjectString- Not documented.
messageString- the message to post
Throws
postOnWall
public void postOnWall(String userId, String message, ActionListener callback)
throws IOExceptionPost a message on the users wall
Parameters
userIdString- the userId
messageString- the message to post
callbackActionListener- Not documented.
Throws
postOnWall
public void postOnWall(String userId, String message, String name, String link, String description, String picture, String caption, ActionListener callback)
throws IOExceptionPost a message on the users wall
Parameters
userIdString- the userId
messageString- the message to post
nameString- Not documented.
linkString- Not documented.
descriptionString- Not documented.
pictureString- Not documented.
captionString- Not documented.
callbackActionListener- Not documented.
Throws
postLike
public void postLike(String postId, ActionListener callback)
throws IOExceptionPost like on a given post
Parameters
postIdString- the post Id
callbackActionListener- Not documented.
Throws
postComment
public void postComment(String postId, String message, ActionListener callback)
throws IOExceptionPost a comment on a given post
Parameters
postIdString- the post id
messageString- the message to post
callbackActionListener- Not documented.
Throws
createNote
public void createNote(String userId, String subject, String message, ActionListener callback)
throws IOExceptionPost a note onto the users wall
Parameters
userIdString- the userId
subjectString- Not documented.
messageString- the message to post
callbackActionListener- Not documented.
Throws
getUserNotifications
public void getUserNotifications(String userId, String startTime, boolean includeRead, DefaultListModel notifications, ActionListener<NetworkEvent> callback)
throws IOExceptionGets the user notifications (this method uses the legacy rest api see http://developers.facebook.com/docs/reference/rest/)
Parameters
userIdString- the user id
startTimeString- 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.
includeReadboolean- Indicates whether to include notifications that have already been read. By default, notifications a user has read are not included.
notificationsDefaultListModel- store notifications results into the given model, each entry is an Hashtable Object contaning the Object data
callbackActionListener<NetworkEvent>- the callback that should be updated when the data arrives
Throws
getUsersDetails
public void getUsersDetails(String[] usersIds, String[] fields, ActionListener<NetworkEvent> callback)
throws IOExceptionGets users requested details ((this method uses the legacy rest api see http://developers.facebook.com/docs/reference/rest/))
Parameters
usersIdsString[]- the users to query
fieldsString[]- which fields to query on the users see http://developers.facebook.com/docs/reference/rest/users.getInfo/
callbackActionListener<NetworkEvent>- 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
getUserEvents
public void getUserEvents(String userId, DefaultListModel events, ActionListener callback)
throws IOExceptionGets the user events
Parameters
userIdString- the user id
eventsDefaultListModel- store events results into the given model, each entry is an Hashtable Object contaning the Object data
callbackActionListener- the callback that should be updated when the data arrives
Throws
search
public void search(String objectType, String query, DefaultListModel results, ActionListener callback)
throws IOExceptionSerach for facebook objects
Parameters
objectTypeString- one of each: post, user, page, event, group, place, checkin
queryString- the query string to search for
resultsDefaultListModel- store results onto the given model, each entry is an Hashtable Object contaning the Object data
callbackActionListener- the callback that should be updated when the data arrives
Throws
killCurrentRequest
public void killCurrentRequest()Kills the current request.
addResponseCodeListener
public void addResponseCodeListener(ActionListener a)Adds a response listener on the requests
Parameters
aActionListener- response listener
removeResponseCodeListener
public void removeResponseCodeListener(ActionListener a)Removes a response listener
cleanTempStorage
public void cleanTempStorage()Deletes all temp storage.