|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.netmera.facebook.Facebook
public class Facebook
Main Facebook object for interacting with the Facebook developer API. Provides methods to log in and log out a user, make requests using the REST and Graph APIs, and start user interface interactions with the API (such as pop-ups promoting for credentials, permissions, stream posts, etc.)
Nested Class Summary | |
---|---|
static interface |
Facebook.DialogListener
Callback interface for dialog requests. |
static interface |
Facebook.ServiceListener
Callback interface for service requests. |
Field Summary | |
---|---|
static java.lang.String |
ATTRIBUTION_ID_COLUMN_NAME
|
static android.net.Uri |
ATTRIBUTION_ID_CONTENT_URI
|
static java.lang.String |
CANCEL_URI
|
static java.lang.String |
EXPIRES
|
static java.lang.String |
FB_APP_SIGNATURE
|
static int |
FORCE_DIALOG_AUTH
|
static java.lang.String |
REDIRECT_URI
|
static java.lang.String |
SINGLE_SIGN_ON_DISABLED
|
static java.lang.String |
TOKEN
|
Constructor Summary | |
---|---|
Facebook(java.lang.String appId)
Constructor for Facebook object. |
Method Summary | |
---|---|
void |
asyncLogout(android.content.Context context)
|
void |
authorize(android.app.Activity activity,
Facebook.DialogListener listener)
Default authorize method. |
void |
authorize(android.app.Activity activity,
java.lang.String[] permissions,
Facebook.DialogListener listener)
Authorize method that grants custom permissions. |
void |
authorize(android.app.Activity activity,
java.lang.String[] permissions,
int activityCode,
Facebook.DialogListener listener)
Full authorize method. |
void |
authorizeCallback(int requestCode,
int resultCode,
android.content.Intent data)
IMPORTANT: This method must be invoked at the top of the calling activity's onActivityResult() function or Facebook authentication will not function properly! |
void |
dialog(android.content.Context context,
java.lang.String action,
android.os.Bundle parameters,
Facebook.DialogListener listener)
Generate a UI dialog for the request action in the given Android context with the provided parameters. |
void |
dialog(android.content.Context context,
java.lang.String action,
Facebook.DialogListener listener)
Generate a UI dialog for the request action in the given Android context. |
boolean |
extendAccessToken(android.content.Context context,
Facebook.ServiceListener serviceListener)
Refresh OAuth access token method. |
boolean |
extendAccessTokenIfNeeded(android.content.Context context,
Facebook.ServiceListener serviceListener)
Calls extendAccessToken if shouldExtendAccessToken returns true. |
long |
getAccessExpires()
Retrieve the current session's expiration time (in milliseconds since Unix epoch), or 0 if the session doesn't expire or doesn't exist. |
java.lang.String |
getAccessToken()
Retrieve the OAuth 2.0 access token for API access: treat with care. |
java.lang.String |
getAppId()
|
static java.lang.String |
getAttributionId(android.content.ContentResolver contentResolver)
Get Attribution ID for app install conversion tracking. |
long |
getLastAccessUpdate()
Retrieve the last time the token was updated (in milliseconds since the Unix epoch), or 0 if the token has not been set. |
boolean |
getShouldAutoPublishInstall()
Get the auto install publish setting. |
boolean |
isSessionValid()
|
java.lang.String |
logout(android.content.Context context)
Invalidate the current user session by removing the access token in memory, clearing the browser cookie, and calling auth.expireSession through the API. |
boolean |
publishInstall(android.content.Context context)
Manually publish install attribution to the facebook graph. |
java.lang.String |
request(android.os.Bundle parameters)
Make a request to Facebook's old (pre-graph) API with the given parameters. |
java.lang.String |
request(java.lang.String graphPath)
Make a request to the Facebook Graph API without any parameters. |
java.lang.String |
request(java.lang.String graphPath,
android.os.Bundle parameters)
Make a request to the Facebook Graph API with the given string parameters using an HTTP GET (default method). |
java.lang.String |
request(java.lang.String graphPath,
android.os.Bundle params,
java.lang.String httpMethod)
Synchronously make a request to the Facebook Graph API with the given HTTP method and string parameters. |
void |
setAccessExpires(long time)
Set the current session's expiration time (in milliseconds since Unix epoch), or 0 if the session doesn't expire. |
void |
setAccessExpiresIn(java.lang.String expiresIn)
Set the current session's duration (in seconds since Unix epoch), or "0" if session doesn't expire. |
void |
setAccessToken(java.lang.String token)
Set the OAuth 2.0 access token for API access. |
void |
setAppId(java.lang.String appId)
|
void |
setShouldAutoPublishInstall(boolean value)
Sets whether auto publishing of installs will occur. |
void |
setTokenFromCache(java.lang.String accessToken,
long accessExpires,
long lastAccessUpdate)
Restore the token, expiration time, and last update time from cached values. |
boolean |
shouldExtendAccessToken()
Check if the access token requires refreshing. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String REDIRECT_URI
public static final java.lang.String CANCEL_URI
public static final java.lang.String TOKEN
public static final java.lang.String EXPIRES
public static final java.lang.String SINGLE_SIGN_ON_DISABLED
public static final android.net.Uri ATTRIBUTION_ID_CONTENT_URI
public static final java.lang.String ATTRIBUTION_ID_COLUMN_NAME
public static final int FORCE_DIALOG_AUTH
public static final java.lang.String FB_APP_SIGNATURE
Constructor Detail |
---|
public Facebook(java.lang.String appId)
appId
- Your Facebook application ID. Found at
www.facebook.com/developers/apps.php.Method Detail |
---|
public void authorize(android.app.Activity activity, Facebook.DialogListener listener)
public void authorize(android.app.Activity activity, java.lang.String[] permissions, Facebook.DialogListener listener)
public void authorize(android.app.Activity activity, java.lang.String[] permissions, int activityCode, Facebook.DialogListener listener)
activity
- The Android activity in which we want to display the
authorization dialog.permissions
- A list of permissions required for this application: e.g.
"read_stream", "publish_stream", "offline_access", etc. see
http://developers.facebook.com/docs/authentication/permissions
This parameter should not be null -- if you do not require any
permissions, then pass in an empty String array.activityCode
- Single sign-on requires an activity result to be called back
to the client application -- if you are waiting on other
activities to return data, pass a custom activity code here to
avoid collisions. If you would like to force the use of legacy
dialog-based authorization, pass FORCE_DIALOG_AUTH for this
parameter. Otherwise just omit this parameter and Facebook
will use a suitable default. See
http://developer.android.com/reference/android/
app/Activity.html for more information.listener
- Callback interface for notifying the calling application when
the authentication dialog has completed, failed, or been
canceled.public void authorizeCallback(int requestCode, int resultCode, android.content.Intent data)
public boolean extendAccessToken(android.content.Context context, Facebook.ServiceListener serviceListener)
context
- The Android Context that will be used to bind to the Facebook
RefreshToken ServiceserviceListener
- Callback interface for notifying the calling application when
the refresh request has completed or failed (can be null). In
case of a success a new token can be found inside the result
Bundle under Facebook.ACCESS_TOKEN key.
public boolean extendAccessTokenIfNeeded(android.content.Context context, Facebook.ServiceListener serviceListener)
public boolean shouldExtendAccessToken()
public java.lang.String logout(android.content.Context context) throws java.net.MalformedURLException, java.io.IOException
context
- The Android context in which the logout should be called: it
should be the same context in which the login occurred in
order to clear any stored cookies
java.io.IOException
java.net.MalformedURLException
public void asyncLogout(android.content.Context context)
public java.lang.String request(android.os.Bundle parameters) throws java.net.MalformedURLException, java.io.IOException
Bundle parameters = new Bundle();
parameters.putString("method", "auth.expireSession");
String response = request(parameters);
parameters
- Key-value pairs of parameters to the request. Refer to the
documentation: one of the parameters must be "method".
java.io.IOException
- if a network error occurs
java.net.MalformedURLException
- if accessing an invalid endpoint
java.lang.IllegalArgumentException
- if one of the parameters is not "method"public java.lang.String request(java.lang.String graphPath) throws java.net.MalformedURLException, java.io.IOException
graphPath
- Path to resource in the Facebook graph, e.g., to fetch data
about the currently logged authenticated user, provide "me",
which will fetch http://graph.facebook.com/me
java.io.IOException
java.net.MalformedURLException
public java.lang.String request(java.lang.String graphPath, android.os.Bundle parameters) throws java.net.MalformedURLException, java.io.IOException
graphPath
- Path to resource in the Facebook graph, e.g., to fetch data
about the currently logged authenticated user, provide "me",
which will fetch http://graph.facebook.com/meparameters
- key-value string parameters, e.g. the path "search" with
parameters "q" : "facebook" would produce a query for the
following graph resource:
https://graph.facebook.com/search?q=facebook
java.io.IOException
java.net.MalformedURLException
public java.lang.String request(java.lang.String graphPath, android.os.Bundle params, java.lang.String httpMethod) throws java.io.FileNotFoundException, java.net.MalformedURLException, java.io.IOException
graphPath
- Path to resource in the Facebook graph, e.g., to fetch data
about the currently logged authenticated user, provide "me",
which will fetch http://graph.facebook.com/meparams
- Key-value string parameters, e.g. the path "search" with
parameters {"q" : "facebook"} would produce a query for the
following graph resource:
https://graph.facebook.com/search?q=facebookhttpMethod
- http verb, e.g. "GET", "POST", "DELETE"
java.io.IOException
java.net.MalformedURLException
java.io.FileNotFoundException
public void dialog(android.content.Context context, java.lang.String action, Facebook.DialogListener listener)
context
- The Android context in which we will generate this dialog.action
- String representation of the desired method: e.g. "login",
"stream.publish", ...listener
- Callback interface to notify the application when the dialog
has completed.public void dialog(android.content.Context context, java.lang.String action, android.os.Bundle parameters, Facebook.DialogListener listener)
context
- The Android context in which we will generate this dialog.action
- String representation of the desired method: e.g. "feed" ...parameters
- String key-value pairs to be passed as URL parameters.listener
- Callback interface to notify the application when the dialog
has completed.public boolean isSessionValid()
public java.lang.String getAccessToken()
public long getAccessExpires()
public long getLastAccessUpdate()
public void setTokenFromCache(java.lang.String accessToken, long accessExpires, long lastAccessUpdate)
accessToken
- - access tokenaccessExpires
- - access token expiration timelastAccessUpdate
- - timestamp of the last token updatepublic void setAccessToken(java.lang.String token)
token
- - access tokenpublic void setAccessExpires(long time)
time
- - timestamp in millisecondspublic void setAccessExpiresIn(java.lang.String expiresIn)
expiresIn
- - duration in seconds (or 0 if the session doesn't expire)public java.lang.String getAppId()
public void setAppId(java.lang.String appId)
public static java.lang.String getAttributionId(android.content.ContentResolver contentResolver)
contentResolver
-
public boolean getShouldAutoPublishInstall()
public void setShouldAutoPublishInstall(boolean value)
value
- public boolean publishInstall(android.content.Context context)
context
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |