com.facebook.api
Class Facebook

java.lang.Object
  extended by com.facebook.api.Facebook

public class Facebook
extends java.lang.Object

Utility class to handle authorization and authentication of requests. Objects of this class are meant to be created for every request. They are stateless and are not supposed to be kept in the session.


Field Summary
protected  FacebookRestClient apiClient
           
protected  java.lang.String apiKey
           
protected  java.util.Map<java.lang.String,java.lang.String> fbParams
           
protected  java.lang.String secret
           
protected  java.lang.Long user
           
 
Constructor Summary
Facebook(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String apiKey, java.lang.String secret)
           
 
Method Summary
 java.lang.String doGetSession(java.lang.String authToken)
           
static java.lang.String generateSig(java.util.Map<java.lang.String,java.lang.String> params, java.lang.String secret)
           
 FacebookRestClient get_api_client()
          Synonym for getFacebookRestClient()
 java.lang.Long get_loggedin_user()
          Synonym for getUser()
 java.lang.String getAddUrl(java.lang.String next)
          Returns the url that facebook uses to prompt the user to add this application.
 java.lang.String getApiKey()
          Returns the api key used to initialize this object.
 java.lang.Long getCanvasUser()
           
 FacebookRestClient getFacebookRestClient()
          Returns the internal FacebookRestClient object.
static java.lang.String getFacebookUrl(java.lang.String subDomain)
          Returns a url to a facebook sub-domain
 java.util.List<java.lang.Long> getFriends()
           
 java.lang.String getLoginUrl(java.lang.String next, boolean canvas)
          Returns the url that facebook uses to prompt the user to login to this application.
 java.lang.Long getPageId()
           
 java.lang.String getProfileSessionKey()
           
 java.lang.Long getProfileUpdateTime()
           
 java.lang.Long getProfileUser()
           
 java.lang.String getSecret()
          Returns the secret key used to initialize this object.
 java.lang.String getSessionKey()
          Returns the session key of the logged in user.
 java.lang.Long getUser()
          Returns the user id of the logged in user associated with this object
 boolean inFbCanvas()
          Returns true if the application is in a canvas.
 boolean inFrame()
          Returns true if the application is in a frame or a canvas.
 boolean isAdded()
           
 boolean isInCanvas()
           
 boolean isInProfileTab()
           
 boolean isInstalled()
           
 boolean isLogin()
           
 boolean isPageAdded()
           
 boolean isUninstall()
           
 boolean requireAdd(java.lang.String next)
          Deprecated. Use requireLogin now instead of requireAdd.
 boolean requireFrame(java.lang.String next)
          Forces the application to be in a frame.
 boolean requireLogin(java.lang.String next)
          Forces the user to log in to this application.
 boolean verifySignature(java.util.Map<java.lang.String,java.lang.String> params, java.lang.String expected_sig)
          Verifies that the signature of the parameters is valid
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

apiClient

protected FacebookRestClient apiClient

apiKey

protected java.lang.String apiKey

secret

protected java.lang.String secret

fbParams

protected java.util.Map<java.lang.String,java.lang.String> fbParams

user

protected java.lang.Long user
Constructor Detail

Facebook

public Facebook(javax.servlet.http.HttpServletRequest request,
                javax.servlet.http.HttpServletResponse response,
                java.lang.String apiKey,
                java.lang.String secret)
Method Detail

getFacebookRestClient

public FacebookRestClient getFacebookRestClient()
Returns the internal FacebookRestClient object.

Returns:

get_api_client

public FacebookRestClient get_api_client()
Synonym for getFacebookRestClient()

Returns:

getSecret

public java.lang.String getSecret()
Returns the secret key used to initialize this object.

Returns:

getApiKey

public java.lang.String getApiKey()
Returns the api key used to initialize this object.

Returns:

doGetSession

public java.lang.String doGetSession(java.lang.String authToken)

inFrame

public boolean inFrame()
Returns true if the application is in a frame or a canvas.

Returns:

inFbCanvas

public boolean inFbCanvas()
Returns true if the application is in a canvas.

Returns:

isAdded

public boolean isAdded()

isLogin

public boolean isLogin()

get_loggedin_user

public java.lang.Long get_loggedin_user()
Synonym for getUser()

Returns:

getUser

public java.lang.Long getUser()
Returns the user id of the logged in user associated with this object

Returns:

getSessionKey

public java.lang.String getSessionKey()
Returns the session key of the logged in user.

Returns:

requireLogin

public boolean requireLogin(java.lang.String next)
Forces the user to log in to this application. If the user hasn't logged in yet, this method issues a url redirect. NOTE: You should return immediately if this returns true. Example usage: if(facebook.requireLogin("")) return;

Parameters:
next - the value for the 'next' request paramater that is appended to facebook's login screen. This should be an emptry string if you want it to go to your base canvas url.
Returns:
true if the user hasn't logged in yet and a redirect was issued.

requireAdd

public boolean requireAdd(java.lang.String next)
Deprecated. Use requireLogin now instead of requireAdd.

Forces the user to add this application. If the user hasn't added it yet, this method issues a url redirect.

Parameters:
next - the value for the 'next' request paramater that is appended to facebook's add screen.
Returns:
true if the user hasn't added the application yet and a redirect was issued.
See Also:
http://forum.developers.facebook.com/viewtopic.php?id=15734

requireFrame

public boolean requireFrame(java.lang.String next)
Forces the application to be in a frame. If it is not in a frame, this method issues a url redirect.

Parameters:
next - the value for the 'next' request paramater that is appended to facebook's login screen.
Returns:
true if a redirect was issued, false otherwise.

getLoginUrl

public java.lang.String getLoginUrl(java.lang.String next,
                                    boolean canvas)
Returns the url that facebook uses to prompt the user to login to this application.

Parameters:
next - indicates the page to which facebook should redirect the user has logged in.
Returns:

getAddUrl

public java.lang.String getAddUrl(java.lang.String next)
Returns the url that facebook uses to prompt the user to add this application.

Parameters:
next - indicates the page to which facebook should redirect the user after the application is added.
Returns:

getFacebookUrl

public static java.lang.String getFacebookUrl(java.lang.String subDomain)
Returns a url to a facebook sub-domain

Parameters:
subDomain -
Returns:

generateSig

public static java.lang.String generateSig(java.util.Map<java.lang.String,java.lang.String> params,
                                           java.lang.String secret)

verifySignature

public boolean verifySignature(java.util.Map<java.lang.String,java.lang.String> params,
                               java.lang.String expected_sig)
Verifies that the signature of the parameters is valid

Parameters:
params - a map of the parameters. Typically these are the request parameters that start with "fb_sig"
expected_sig - the expected signature
Returns:

getFriends

public java.util.List<java.lang.Long> getFriends()

getProfileUser

public java.lang.Long getProfileUser()

isUninstall

public boolean isUninstall()

getProfileUpdateTime

public java.lang.Long getProfileUpdateTime()

getProfileSessionKey

public java.lang.String getProfileSessionKey()

getPageId

public java.lang.Long getPageId()

isPageAdded

public boolean isPageAdded()

isInstalled

public boolean isInstalled()

isInProfileTab

public boolean isInProfileTab()

isInCanvas

public boolean isInCanvas()

getCanvasUser

public java.lang.Long getCanvasUser()


Copyright © 2008. All Rights Reserved.