com.google.code.facebookapi
Class BasicClient

java.lang.Object
  extended by com.google.code.facebookapi.BasicClient

public class BasicClient
extends java.lang.Object

Basic client taking care of rest call mechanics (signing, etc) to facebook. No api knowledge, nor response interpretation is planned.


Field Summary
protected  java.lang.String _apiKey
           
protected  boolean _isDesktop
           
protected  int _readTimeout
           
protected  java.lang.String _secret
           
protected  java.net.URL _serverUrl
           
protected  int _timeout
           
protected  boolean batchMode
           
protected  java.lang.Long cacheSessionExpires
           
protected  java.lang.String cacheSessionKey
           
protected  java.lang.String cacheSessionSecret
          filled in when session is established only used for desktop apps
protected static java.lang.String CRLF
           
protected static org.apache.commons.logging.Log log
           
protected  java.lang.String permissionsApiKey
           
protected static java.lang.String PREF
           
protected  java.util.List<com.google.code.facebookapi.BatchQuery> queries
           
protected  java.lang.String rawResponse
           
protected static int UPLOAD_BUFFER_SIZE
           
 
Constructor Summary
protected BasicClient(java.lang.String apiKey, java.lang.String secret)
           
protected BasicClient(java.lang.String apiKey, java.lang.String secret, int timeout)
           
protected BasicClient(java.lang.String apiKey, java.lang.String secret, java.lang.String sessionKey)
           
protected BasicClient(java.lang.String apiKey, java.lang.String secret, java.lang.String sessionKey, int timeout)
           
protected BasicClient(java.net.URL serverUrl, java.lang.String apiKey, java.lang.String secret, java.lang.String sessionKey)
           
protected BasicClient(java.net.URL serverUrl, java.lang.String apiKey, java.lang.String secret, java.lang.String sessionKey, int timeout)
           
protected BasicClient(java.net.URL serverUrl, java.lang.String apiKey, java.lang.String secret, java.lang.String sessionKey, int timeout, int readTimeout)
           
 
Method Summary
 java.lang.String batch_run(java.lang.String responseFormat, java.lang.String methods, boolean serial)
           
 void beginBatch()
           
 void beginPermissionsMode(java.lang.String apiKey)
           
 java.lang.String callMethod(java.lang.String responseFormat, IFacebookMethod method, java.util.Collection<Pair<java.lang.String,java.lang.CharSequence>> paramPairs)
          Call the specified method, with the given parameters, and return a DOM tree with the results.
 java.lang.String callMethod(java.lang.String responseFormat, IFacebookMethod method, java.util.Collection<Pair<java.lang.String,java.lang.CharSequence>> paramPairs, java.lang.String fileName, java.io.InputStream fileStream)
           
protected  java.lang.String callMethod(java.lang.String responseFormat, IFacebookMethod method, Pair<java.lang.String,java.lang.CharSequence>... paramPairs)
          Call the specified method, with the given parameters, and return a DOM tree with the results.
static java.lang.String encodeMethods(java.util.List<com.google.code.facebookapi.BatchQuery> queryList)
           
 void endPermissionsMode()
           
 java.util.List<java.lang.String> executeBatch(java.lang.String responseFormat, boolean serial)
          Returns a list of String raw responses which will be further broken down by the adapters into the actual individual responses.
 java.lang.String getApiKey()
           
 java.lang.Long getCacheSessionExpires()
           
 java.lang.String getCacheSessionKey()
           
 java.lang.String getCacheSessionSecret()
           
 java.util.List<com.google.code.facebookapi.BatchQuery> getQueries()
           
 java.lang.String getRawResponse()
           
 java.lang.String getSecret()
           
 java.lang.String getSessionSecret()
          Gets the session-token used by Facebook to authenticate a desktop application.
 boolean isBatchMode()
           
 boolean isDesktop()
           
protected  java.lang.String postFileRequest(java.util.Map<java.lang.String,java.lang.String> params, java.lang.String fileName, java.io.InputStream fileStream)
          Helper function for posting a request that includes raw file data, eg #photos_upload.
 void setCacheSessionExpires(java.lang.Long cacheSessionExpires)
           
 void setCacheSessionKey(java.lang.String cacheSessionKey)
           
 void setCacheSessionSecret(java.lang.String cacheSessionSecret)
           
 void setServerUrl(java.lang.String newUrl)
           
 void setSessionSecret(java.lang.String key)
          Allows the session-token to be manually overridden when running a desktop application.
 
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

CRLF

protected static final java.lang.String CRLF
See Also:
Constant Field Values

PREF

protected static final java.lang.String PREF
See Also:
Constant Field Values

UPLOAD_BUFFER_SIZE

protected static final int UPLOAD_BUFFER_SIZE
See Also:
Constant Field Values

_serverUrl

protected java.net.URL _serverUrl

_timeout

protected int _timeout

_readTimeout

protected int _readTimeout

_apiKey

protected final java.lang.String _apiKey

_secret

protected final java.lang.String _secret

_isDesktop

protected boolean _isDesktop

cacheSessionKey

protected java.lang.String cacheSessionKey

cacheSessionExpires

protected java.lang.Long cacheSessionExpires

cacheSessionSecret

protected java.lang.String cacheSessionSecret
filled in when session is established only used for desktop apps


rawResponse

protected java.lang.String rawResponse

batchMode

protected boolean batchMode

queries

protected java.util.List<com.google.code.facebookapi.BatchQuery> queries

permissionsApiKey

protected java.lang.String permissionsApiKey
Constructor Detail

BasicClient

protected BasicClient(java.lang.String apiKey,
                      java.lang.String secret)

BasicClient

protected BasicClient(java.lang.String apiKey,
                      java.lang.String secret,
                      int timeout)

BasicClient

protected BasicClient(java.lang.String apiKey,
                      java.lang.String secret,
                      java.lang.String sessionKey)

BasicClient

protected BasicClient(java.lang.String apiKey,
                      java.lang.String secret,
                      java.lang.String sessionKey,
                      int timeout)

BasicClient

protected BasicClient(java.net.URL serverUrl,
                      java.lang.String apiKey,
                      java.lang.String secret,
                      java.lang.String sessionKey,
                      int timeout)

BasicClient

protected BasicClient(java.net.URL serverUrl,
                      java.lang.String apiKey,
                      java.lang.String secret,
                      java.lang.String sessionKey,
                      int timeout,
                      int readTimeout)

BasicClient

protected BasicClient(java.net.URL serverUrl,
                      java.lang.String apiKey,
                      java.lang.String secret,
                      java.lang.String sessionKey)
Method Detail

isBatchMode

public boolean isBatchMode()

getQueries

public java.util.List<com.google.code.facebookapi.BatchQuery> getQueries()

isDesktop

public boolean isDesktop()

getRawResponse

public java.lang.String getRawResponse()

getApiKey

public java.lang.String getApiKey()

getSecret

public java.lang.String getSecret()

beginPermissionsMode

public void beginPermissionsMode(java.lang.String apiKey)

endPermissionsMode

public void endPermissionsMode()

getSessionSecret

public java.lang.String getSessionSecret()
Gets the session-token used by Facebook to authenticate a desktop application. If your application does not run in desktop mode, than this field is not relevent to you.

Returns:
the desktop-app session token.

setSessionSecret

public void setSessionSecret(java.lang.String key)
Allows the session-token to be manually overridden when running a desktop application. If your application does not run in desktop mode, then setting this field will have no effect. If you set an incorrect value here, your application will probably fail to run.

Parameters:
key - the new value to set. Incorrect values may cause your application to fail to run.

getCacheSessionSecret

public java.lang.String getCacheSessionSecret()

setCacheSessionSecret

public void setCacheSessionSecret(java.lang.String cacheSessionSecret)

getCacheSessionExpires

public java.lang.Long getCacheSessionExpires()

setCacheSessionExpires

public void setCacheSessionExpires(java.lang.Long cacheSessionExpires)

getCacheSessionKey

public java.lang.String getCacheSessionKey()

setCacheSessionKey

public void setCacheSessionKey(java.lang.String cacheSessionKey)

callMethod

protected java.lang.String callMethod(java.lang.String responseFormat,
                                      IFacebookMethod method,
                                      Pair<java.lang.String,java.lang.CharSequence>... paramPairs)
                               throws FacebookException
Call the specified method, with the given parameters, and return a DOM tree with the results.

Parameters:
method - the fieldName of the method
paramPairs - a list of arguments to the method
Throws:
java.lang.Exception - with a description of any errors given to us by the server.
FacebookException

callMethod

public java.lang.String callMethod(java.lang.String responseFormat,
                                   IFacebookMethod method,
                                   java.util.Collection<Pair<java.lang.String,java.lang.CharSequence>> paramPairs)
                            throws FacebookException
Call the specified method, with the given parameters, and return a DOM tree with the results.

Parameters:
method - the fieldName of the method
paramPairs - a list of arguments to the method
Throws:
java.lang.Exception - with a description of any errors given to us by the server.
FacebookException

callMethod

public java.lang.String callMethod(java.lang.String responseFormat,
                                   IFacebookMethod method,
                                   java.util.Collection<Pair<java.lang.String,java.lang.CharSequence>> paramPairs,
                                   java.lang.String fileName,
                                   java.io.InputStream fileStream)
                            throws FacebookException
Throws:
FacebookException

postFileRequest

protected java.lang.String postFileRequest(java.util.Map<java.lang.String,java.lang.String> params,
                                           java.lang.String fileName,
                                           java.io.InputStream fileStream)
                                    throws java.io.IOException
Helper function for posting a request that includes raw file data, eg #photos_upload.

Parameters:
methodName - the name of the method
params - request parameters (not including the file)
doEncode - whether to UTF8-encode the parameters
Returns:
an InputStream with the request response
Throws:
java.io.IOException
See Also:
#photos_upload

beginBatch

public void beginBatch()

batch_run

public java.lang.String batch_run(java.lang.String responseFormat,
                                  java.lang.String methods,
                                  boolean serial)
                           throws FacebookException
Throws:
FacebookException

setServerUrl

public void setServerUrl(java.lang.String newUrl)

executeBatch

public java.util.List<java.lang.String> executeBatch(java.lang.String responseFormat,
                                                     boolean serial)
                                              throws FacebookException
Returns a list of String raw responses which will be further broken down by the adapters into the actual individual responses. One string is returned per 20 methods in the batch.

Throws:
FacebookException

encodeMethods

public static java.lang.String encodeMethods(java.util.List<com.google.code.facebookapi.BatchQuery> queryList)
                                      throws FacebookException
Throws:
FacebookException


Copyright © 2009. All Rights Reserved.