com.google.code.facebookapi
Class FacebookWebappHelper<T>

java.lang.Object
  extended by com.google.code.facebookapi.FacebookWebappHelper<T>

public class FacebookWebappHelper<T>
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  IFacebookRestClient<T> apiClient
           
protected  java.lang.String apiKey
           
protected  java.util.Map<java.lang.String,java.lang.String> fbParams
           
protected static org.apache.commons.logging.Log log
           
protected  java.lang.String secret
           
protected  java.lang.Long user
           
 
Constructor Summary
FacebookWebappHelper(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String apiKey, java.lang.String secret)
          Deprecated. please use different constructor, or factory methods
FacebookWebappHelper(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String apiKey, java.lang.String secret, IFacebookRestClient<T> apiClient)
           
 
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)
           
 IFacebookRestClient<T> 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.
 IFacebookRestClient<T> getFacebookRestClient()
          Returns the internal FacebookRestClient object.
static java.lang.String getFacebookUrl(java.lang.String subDomain)
          Returns a url to a facebook sub-domain
 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.String getSecret()
          Returns the secret key used to initialize this object.
 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()
          Deprecated. 
 boolean isLogin()
           
 boolean isUninstall()
          Returns true if UNINSTALL param exists and is 1.
static FacebookWebappHelper<java.lang.Object> newInstanceJaxb(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String apiKey, java.lang.String secret)
           
static FacebookWebappHelper<java.lang.Object> newInstanceJson(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String apiKey, java.lang.String secret)
           
static FacebookWebappHelper<org.w3c.dom.Document> newInstanceXml(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String apiKey, java.lang.String secret)
           
 void redirect(java.lang.String url)
           
 boolean requireAdd(java.lang.String next)
          Deprecated. 
 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

log

protected static org.apache.commons.logging.Log log

apiClient

protected IFacebookRestClient<T> 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

FacebookWebappHelper

@Deprecated
public FacebookWebappHelper(javax.servlet.http.HttpServletRequest request,
                                       javax.servlet.http.HttpServletResponse response,
                                       java.lang.String apiKey,
                                       java.lang.String secret)
Deprecated. please use different constructor, or factory methods


FacebookWebappHelper

public FacebookWebappHelper(javax.servlet.http.HttpServletRequest request,
                            javax.servlet.http.HttpServletResponse response,
                            java.lang.String apiKey,
                            java.lang.String secret,
                            IFacebookRestClient<T> apiClient)
Method Detail

newInstanceXml

public static FacebookWebappHelper<org.w3c.dom.Document> newInstanceXml(javax.servlet.http.HttpServletRequest request,
                                                                        javax.servlet.http.HttpServletResponse response,
                                                                        java.lang.String apiKey,
                                                                        java.lang.String secret)

newInstanceJson

public static FacebookWebappHelper<java.lang.Object> newInstanceJson(javax.servlet.http.HttpServletRequest request,
                                                                     javax.servlet.http.HttpServletResponse response,
                                                                     java.lang.String apiKey,
                                                                     java.lang.String secret)

newInstanceJaxb

public static FacebookWebappHelper<java.lang.Object> newInstanceJaxb(javax.servlet.http.HttpServletRequest request,
                                                                     javax.servlet.http.HttpServletResponse response,
                                                                     java.lang.String apiKey,
                                                                     java.lang.String secret)

getFacebookRestClient

public IFacebookRestClient<T> getFacebookRestClient()
Returns the internal FacebookRestClient object.


get_api_client

public IFacebookRestClient<T> get_api_client()
Synonym for getFacebookRestClient()


getSecret

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


getApiKey

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


doGetSession

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

redirect

public void redirect(java.lang.String url)

inFrame

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


inFbCanvas

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


isAdded

@Deprecated
public boolean isAdded()
Deprecated. 


isUninstall

public boolean isUninstall()
Returns true if UNINSTALL param exists and is 1.


isLogin

public boolean isLogin()

get_loggedin_user

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


getUser

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


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.

Parameters:
next - the value for the 'next' request paramater that is appended to facebook's login screen.
Returns:
true if the user hasn't logged in yet and a redirect was issued.

requireAdd

@Deprecated
public boolean requireAdd(java.lang.String next)
Deprecated. 

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.

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.

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.

getFacebookUrl

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

Parameters:
subDomain -

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


Copyright © 2010. All Rights Reserved.