Class DefaultFacebookClient
- All Implemented Interfaces:
FacebookClient
- Direct Known Subclasses:
DefaultInstagramClient
,DefaultInstagramLoginClient
,DefaultThreadsClient
- Author:
- Mark Allen
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final String
Reserved access token parameter name.protected String
Graph API access token.protected boolean
static final String
protected Version
Version of API endpoint.static final String
static final String
protected static final String
Reserved application secret proof parameter name.protected String
Graph API app secret.static final String
static final String
static final String
static final String
static final String
protected static final String
Reserved "result format" parameter name.static final String
protected boolean
By default, this isfalse
, so real http DELETE is usedprotected static final String
Reserved "multiple IDs" parameter name.protected JsonMapper
Handles mapping Facebook response JSON to Java objects.protected static final String
Reserved method override parameter name.static final String
static final String
static final String
static final String
protected WebRequestor
HandlesGET
s andPOST
s to the Facebook API endpoint. -
Constructor Summary
ModifierConstructorDescriptionprotected
DefaultFacebookClient
(Version apiVersion) Creates a Facebook Graph API client with the givenapiVersion
.DefaultFacebookClient
(String accessToken, Version apiVersion) Creates a Facebook Graph API client with the givenaccessToken
.DefaultFacebookClient
(String accessToken, WebRequestor webRequestor, JsonMapper jsonMapper, Version apiVersion) Creates a Facebook Graph API client with the givenaccessToken
.DefaultFacebookClient
(String accessToken, String appSecret, Version apiVersion) Creates a Facebook Graph API client with the givenaccessToken
.DefaultFacebookClient
(String accessToken, String appSecret, WebRequestor webRequestor, JsonMapper jsonMapper, Version apiVersion) Creates a Facebook Graph API client with the givenaccessToken
,webRequestor
, andjsonMapper
. -
Method Summary
Modifier and TypeMethodDescriptionconvertSessionKeysToAccessTokens
(String appId, String secretKey, String... sessionKeys) Converts an arbitrary number ofsessionKeys
to OAuth access tokens.protected String
createBaseUrlForEndpoint
(String apiCall, boolean hasAttachment, boolean hasReel) createClientWithAccessToken
(String accessToken) creates a newFacebookClient
from an old one.protected String
createEndpointForApiCall
(String apiCall, boolean hasAttachment, boolean hasReel) Given an api call (e.g.debugToken
(String inputToken) When working with access tokens, you may need to check what information is associated with them, such as its user or expiry.boolean
deleteObject
(String object, Parameter... parameters) Performs a Graph API delete operation on the givenobject
.executeBatch
(BatchRequest... batchRequests) Executes operations as a batch using the Batch API.executeBatch
(List<BatchRequest> batchRequests) Executes operations as a batch using the Batch API.executeBatch
(List<BatchRequest> batchRequests, List<BinaryAttachment> binaryAttachments) Executes operations as a batch with binary attachments using the Batch API.<T> Connection<T>
fetchConnection
(String connection, Class<T> connectionType, Parameter... parameters) Fetches a Graph APIConnection
type, mapping the result to an instance ofconnectionType
.<T> Connection<T>
fetchConnectionPage
(String connectionPageUrl, Class<T> connectionType) Fetches a previous/next page of a Graph APIConnection
type, mapping the result to an instance ofconnectionType
.fetchDeviceCode
(ScopeBuilder scope) Method to initialize the device access token generation.<T> T
fetchObject
(String object, Class<T> objectType, Parameter... parameters) Fetches a single Graph API object, mapping the result to an instance ofobjectType
.<T> T
fetchObjects
(List<String> ids, Class<T> objectType, Parameter... parameters) Fetches multiple Graph API objects in a single call, mapping the results to an instance ofobjectType
.protected AccessToken
getAccessTokenFromResponse
(String response) fetch the current facebook exception generator implementing theFacebookExceptionGenerator
interfaceprotected String
Returns the base endpoint URL for the Graph API.protected String
Returns the base endpoint URL for the Graph APIs video upload functionality.protected String
Returns the Facebook Reels Upload endpoint URL for handling the Reels Uploadprotected String
getGenericLoginDialogUrl
(String appId, String redirectUri, ScopeBuilder scope, Supplier<String> endpointSupplier, String state, List<Parameter> parameters) Gets theJsonMapper
used to convert Facebook JSON to Java objects.getLoginDialogUrl
(String appId, String redirectUri, ScopeBuilder scope, Parameter... parameters) generates the login dialog urlgetLoginDialogUrl
(String appId, String redirectUri, ScopeBuilder scope, String state, Parameter... parameters) generates the login dialog urlgetLogoutUrl
(String next) generates an logout urlGets theWebRequestor
used to talk to the Facebook API endpoints.boolean
returns if the fallback post method (true
) is used or the http delete (false
)protected String
makeRequest
(String endpoint, boolean executeAsPost, boolean executeAsDelete, List<BinaryAttachment> binaryAttachments, Body body, Parameter... parameters) Coordinates the process of executing the API request GET/POST and processing the response we receive from the endpoint.protected String
makeRequest
(String endpoint, boolean executeAsPost, boolean executeAsDelete, List<BinaryAttachment> binaryAttachments, Parameter... parameters) protected String
makeRequest
(String endpoint, Parameter... parameters) Coordinates the process of executing the API request GET/POST and processing the response we receive from the endpoint.protected String
obtainAppAccessToken
(String appId, String appSecret) Obtains an access token which can be used to perform Graph API operations on behalf of an application instead of a user.obtainAppSecretProof
(String accessToken, String appSecret) Generates anappsecret_proof
value.Method to poll Facebook and fetch the Device Access Token.obtainExtendedAccessToken
(String appId, String appSecret) Convenience method which invokesFacebookClient.obtainExtendedAccessToken(String, String, String)
with the current access token.obtainExtendedAccessToken
(String appId, String appSecret, String accessToken) Obtains an extended access token for the given existing, non-expired, short-lived access_token.Obtain a refreshed Instagram extended access token.obtainUserAccessToken
(String appId, String appSecret, String redirectUri, String verificationCode) Obtains an access token which can be used to perform Graph API operations on behalf of a user.protected Parameter[]
parametersWithAdditionalParameter
(Parameter parameter, Parameter... parameters) Appends the givenparameter
to the givenparameters
array.<T> T
parseSignedRequest
(String signedRequest, String appSecret, Class<T> objectType) Parses a signed request and verifies it against your App Secret.<T> T
publish
(String connection, Class<T> objectType, BinaryAttachment binaryAttachment, Parameter... parameters) Performs a Graph API publish operation on the givenconnection
and includes a file - a photo, for example - in the publish request, and mapping the result to an instance ofobjectType
.<T> T
Performs a Graph API publish operation on the givenconnection
and includes special body in the publish request, and mapping the result to an instance ofobjectType
.<T> T
Performs a Graph API publish operation on the givenconnection
, mapping the result to an instance ofobjectType
.<T> T
publish
(String connection, Class<T> objectType, List<BinaryAttachment> binaryAttachments, Parameter... parameters) Performs a Graph API publish operation on the givenconnection
and includes some files - photos, for example - in the publish request, and mapping the result to an instance ofobjectType
.void
setFacebookEndpointUrls
(FacebookEndpoints facebookEndpointUrls) void
setFacebookExceptionGenerator
(FacebookExceptionGenerator exceptionGenerator) override the default facebook exception generator to provide a custom handling for the facebook error objectsvoid
setHeaderAuthorization
(boolean accessTokenInHttpHeader) Switch between access token in header and access token in query parameters (default)void
setHttpDeleteFallback
(boolean httpDeleteFallback) Set totrue
if the facebook http delete fallback should be used.protected String
toParameterString
(boolean withJsonParameter, Parameter... parameters) Generate the parameter string to be included in the Facebook API request.protected String
toParameterString
(Parameter... parameters) Generate the parameter string to be included in the Facebook API request.protected String
urlDecodeSignedRequestToken
(String signedRequestToken) Decodes a component of a signed request received from Facebook using FB's special URL-encoding strategy.protected String
urlEncodedValueForParameterName
(String name, String value) Gets the URL-encoded version of the givenvalue
for the parameter namedname
.protected void
verifyParameterLegality
(Parameter... parameters) Verifies that the provided parameter names don't collide with the ones we internally pass along to Facebook.protected boolean
verifySignedRequest
(String appSecret, String algorithm, String encodedPayload, byte[] signature) Verifies that the signed request is really from Facebook.
-
Field Details
-
CLIENT_ID
- See Also:
-
APP_ID
- See Also:
-
APP_SECRET
- See Also:
-
SCOPE
- See Also:
-
CANNOT_EXTRACT_ACCESS_TOKEN_MESSAGE
- See Also:
-
PARAM_CLIENT_SECRET
- See Also:
-
CONNECTION
- See Also:
-
CONNECTION_TYPE
- See Also:
-
ALGORITHM
- See Also:
-
PATH_OAUTH_ACCESS_TOKEN
- See Also:
-
REDIRECT_URI
- See Also:
-
GRANT_TYPE
- See Also:
-
CODE
- See Also:
-
accessToken
Graph API access token. -
appSecret
Graph API app secret. -
IDS_PARAM_NAME
Reserved "multiple IDs" parameter name.- See Also:
-
apiVersion
Version of API endpoint. -
httpDeleteFallback
By default, this isfalse
, so real http DELETE is used -
accessTokenInHeader
-
webRequestor
HandlesGET
s andPOST
s to the Facebook API endpoint. -
jsonMapper
Handles mapping Facebook response JSON to Java objects. -
METHOD_PARAM_NAME
Reserved method override parameter name.- See Also:
-
FORMAT_PARAM_NAME
Reserved "result format" parameter name.- See Also:
-
ACCESS_TOKEN_PARAM_NAME
Reserved access token parameter name.- See Also:
-
APP_SECRET_PROOF_PARAM_NAME
Reserved application secret proof parameter name.- See Also:
-
-
Constructor Details
-
DefaultFacebookClient
protected DefaultFacebookClient() -
DefaultFacebookClient
Creates a Facebook Graph API client with the givenapiVersion
.- Parameters:
apiVersion
- Version of the api endpoint
-
DefaultFacebookClient
Creates a Facebook Graph API client with the givenaccessToken
.- Parameters:
accessToken
- A Facebook OAuth access token.apiVersion
- Version of the api endpoint- Since:
- 1.6.14
-
DefaultFacebookClient
Creates a Facebook Graph API client with the givenaccessToken
.- Parameters:
accessToken
- A Facebook OAuth access token.appSecret
- A Facebook application secret.apiVersion
- Version of the api endpoint- Since:
- 1.6.14
-
DefaultFacebookClient
public DefaultFacebookClient(String accessToken, WebRequestor webRequestor, JsonMapper jsonMapper, Version apiVersion) Creates a Facebook Graph API client with the givenaccessToken
.- Parameters:
accessToken
- A Facebook OAuth access token.webRequestor
- TheWebRequestor
implementation to use for sending requests to the API endpoint.jsonMapper
- TheJsonMapper
implementation to use for mapping API response JSON to Java objects.apiVersion
- Version of the api endpoint- Throws:
NullPointerException
- IfjsonMapper
orwebRequestor
isnull
.- Since:
- 1.6.14
-
DefaultFacebookClient
public DefaultFacebookClient(String accessToken, String appSecret, WebRequestor webRequestor, JsonMapper jsonMapper, Version apiVersion) Creates a Facebook Graph API client with the givenaccessToken
,webRequestor
, andjsonMapper
.- Parameters:
accessToken
- A Facebook OAuth access token.appSecret
- A Facebook application secret.webRequestor
- TheWebRequestor
implementation to use for sending requests to the API endpoint.jsonMapper
- TheJsonMapper
implementation to use for mapping API response JSON to Java objects.apiVersion
- Version of the api endpoint- Throws:
NullPointerException
- IfjsonMapper
orwebRequestor
isnull
.
-
-
Method Details
-
setHeaderAuthorization
Switch between access token in header and access token in query parameters (default)- Parameters:
accessTokenInHttpHeader
-true
use access token as header field,false
use access token as query parameter (default)
-
setFacebookExceptionGenerator
override the default facebook exception generator to provide a custom handling for the facebook error objects- Parameters:
exceptionGenerator
- the custom exception generator implementing theFacebookExceptionGenerator
interface
-
getFacebookExceptionGenerator
fetch the current facebook exception generator implementing theFacebookExceptionGenerator
interface- Returns:
- the current facebook exception generator
-
deleteObject
Description copied from interface:FacebookClient
Performs a Graph API delete operation on the givenobject
.- Specified by:
deleteObject
in interfaceFacebookClient
- Parameters:
object
- The ID of the object to delete.parameters
- URL parameters to include in the API call.- Returns:
true
if Facebook indicated that the object was successfully deleted,false
otherwise.
-
fetchConnection
public <T> Connection<T> fetchConnection(String connection, Class<T> connectionType, Parameter... parameters) Description copied from interface:FacebookClient
Fetches a Graph APIConnection
type, mapping the result to an instance ofconnectionType
.- Specified by:
fetchConnection
in interfaceFacebookClient
- Type Parameters:
T
- Java type to map to.- Parameters:
connection
- The name of the connection, e.g."me/feed"
.connectionType
- Connection type token.parameters
- URL parameters to include in the API call (optional).- Returns:
- An instance of type
connectionType
which contains the requested Connection's data. - See Also:
-
fetchConnectionPage
Description copied from interface:FacebookClient
Fetches a previous/next page of a Graph APIConnection
type, mapping the result to an instance ofconnectionType
.- Specified by:
fetchConnectionPage
in interfaceFacebookClient
- Type Parameters:
T
- Java type to map to.- Parameters:
connectionPageUrl
- The URL of the connection page to fetch, usually retrieved viaConnection.getPreviousPageUrl()
orConnection.getNextPageUrl()
.connectionType
- Connection type token.- Returns:
- An instance of type
connectionType
which contains the requested Connection's data. - See Also:
-
fetchObject
Description copied from interface:FacebookClient
Fetches a single Graph API object, mapping the result to an instance ofobjectType
.- Specified by:
fetchObject
in interfaceFacebookClient
- Type Parameters:
T
- Java type to map to.- Parameters:
object
- ID of the object to fetch, e.g."me"
.objectType
- Object type token.parameters
- URL parameters to include in the API call (optional).- Returns:
- An instance of type
objectType
which contains the requested object's data. - See Also:
-
createClientWithAccessToken
Description copied from interface:FacebookClient
creates a newFacebookClient
from an old one.App secret and api version are taken from the original client.
- Specified by:
createClientWithAccessToken
in interfaceFacebookClient
- Parameters:
accessToken
- this accesstoken is used for the new client- Returns:
- a new Facebookclient
-
fetchObjects
Description copied from interface:FacebookClient
Fetches multiple Graph API objects in a single call, mapping the results to an instance ofobjectType
.You'll need to write your own container type (
objectType
) to hold the results. See http://restfb.com for an example of how to do this.- Specified by:
fetchObjects
in interfaceFacebookClient
- Type Parameters:
T
- Java type to map to.- Parameters:
ids
- IDs of the objects to fetch, e.g."me", "arjun"
.objectType
- Object type token.parameters
- URL parameters to include in the API call (optional).- Returns:
- An instance of type
objectType
which contains the requested objects' data. - See Also:
-
publish
public <T> T publish(String connection, Class<T> objectType, List<BinaryAttachment> binaryAttachments, Parameter... parameters) Description copied from interface:FacebookClient
Performs a Graph API publish operation on the givenconnection
and includes some files - photos, for example - in the publish request, and mapping the result to an instance ofobjectType
.- Specified by:
publish
in interfaceFacebookClient
- Type Parameters:
T
- Java type to map to.- Parameters:
connection
- The Connection to publish to.objectType
- Object type token.binaryAttachments
- The files to include in the publish request.parameters
- URL parameters to include in the API call.- Returns:
- An instance of type
objectType
which contains the Facebook response to your publish request. - See Also:
-
publish
public <T> T publish(String connection, Class<T> objectType, BinaryAttachment binaryAttachment, Parameter... parameters) Description copied from interface:FacebookClient
Performs a Graph API publish operation on the givenconnection
and includes a file - a photo, for example - in the publish request, and mapping the result to an instance ofobjectType
.- Specified by:
publish
in interfaceFacebookClient
- Type Parameters:
T
- Java type to map to.- Parameters:
connection
- The Connection to publish to.objectType
- Object type token.binaryAttachment
- The file to include in the publish request.parameters
- URL parameters to include in the API call.- Returns:
- An instance of type
objectType
which contains the Facebook response to your publish request. - See Also:
-
publish
Description copied from interface:FacebookClient
Performs a Graph API publish operation on the givenconnection
, mapping the result to an instance ofobjectType
.- Specified by:
publish
in interfaceFacebookClient
- Type Parameters:
T
- Java type to map to.- Parameters:
connection
- The Connection to publish to.objectType
- Object type token.parameters
- URL parameters to include in the API call.- Returns:
- An instance of type
objectType
which contains the Facebook response to your publish request. - See Also:
-
publish
Description copied from interface:FacebookClient
Performs a Graph API publish operation on the givenconnection
and includes special body in the publish request, and mapping the result to an instance ofobjectType
.- Specified by:
publish
in interfaceFacebookClient
- Type Parameters:
T
- Java type to map to.- Parameters:
connection
- The Connection to publish to.objectType
- Object type token.body
- The body used in the POST request.parameters
- URL parameters to include in the API call.- Returns:
- An instance of type
objectType
which contains the Facebook response to your publish request.
-
getLogoutUrl
Description copied from interface:FacebookClient
generates an logout url- Specified by:
getLogoutUrl
in interfaceFacebookClient
- Parameters:
next
- may be null, url the webpage should redirect after logout- Returns:
- the logout url
-
executeBatch
Description copied from interface:FacebookClient
Executes operations as a batch using the Batch API.- Specified by:
executeBatch
in interfaceFacebookClient
- Parameters:
batchRequests
- The operations to execute.- Returns:
- The execution results in the order in which the requests were specified.
- See Also:
-
executeBatch
Description copied from interface:FacebookClient
Executes operations as a batch using the Batch API.- Specified by:
executeBatch
in interfaceFacebookClient
- Parameters:
batchRequests
- The operations to execute.- Returns:
- The execution results in the order in which the requests were specified.
- See Also:
-
executeBatch
public List<BatchResponse> executeBatch(List<BatchRequest> batchRequests, List<BinaryAttachment> binaryAttachments) Description copied from interface:FacebookClient
Executes operations as a batch with binary attachments using the Batch API.- Specified by:
executeBatch
in interfaceFacebookClient
- Parameters:
batchRequests
- The operations to execute.binaryAttachments
- Binary attachments referenced by the batch requests.- Returns:
- The execution results in the order in which the requests were specified.
- See Also:
-
convertSessionKeysToAccessTokens
public List<AccessToken> convertSessionKeysToAccessTokens(String appId, String secretKey, String... sessionKeys) Description copied from interface:FacebookClient
Converts an arbitrary number ofsessionKeys
to OAuth access tokens.See the Facebook Platform Upgrade Guide for details on how this process works and why you should convert your application's session keys if you haven't already.
- Specified by:
convertSessionKeysToAccessTokens
in interfaceFacebookClient
- Parameters:
appId
- A Facebook application ID.secretKey
- A Facebook application secret key.sessionKeys
- The Old REST API session keys to be converted to OAuth access tokens.- Returns:
- A list of access tokens ordered to correspond to the
sessionKeys
argument list. - See Also:
-
obtainAppAccessToken
Description copied from interface:FacebookClient
Obtains an access token which can be used to perform Graph API operations on behalf of an application instead of a user.- Specified by:
obtainAppAccessToken
in interfaceFacebookClient
- Parameters:
appId
- The ID of the app for which you'd like to obtain an access token.appSecret
- The secret for the app for which you'd like to obtain an access token.- Returns:
- The access token for the application identified by
appId
andappSecret
. - See Also:
-
fetchDeviceCode
Description copied from interface:FacebookClient
Method to initialize the device access token generation.You receive a
DeviceCode
instance and have to show the user theDeviceCode.getVerificationUri()
and theDeviceCode.getUserCode()
. The user have to enter the user code at the verification url.Save the
DeviceCode.getCode()
to use it later, when polling Facebook with theFacebookClient.obtainDeviceAccessToken(java.lang.String)
method.- Specified by:
fetchDeviceCode
in interfaceFacebookClient
- Parameters:
scope
- List of Permissions to request from the person using your app.- Returns:
- Instance of
DeviceCode
including the information to obtain the Device access token
-
obtainDeviceAccessToken
public AccessToken obtainDeviceAccessToken(String code) throws FacebookDeviceTokenCodeExpiredException, FacebookDeviceTokenPendingException, FacebookDeviceTokenDeclinedException, FacebookDeviceTokenSlowdownException Description copied from interface:FacebookClient
Method to poll Facebook and fetch the Device Access Token.You have to use this method to check if the user confirms the authorization.
FacebookOAuthException
can be thrown if the authorization is declined or still pending.- Specified by:
obtainDeviceAccessToken
in interfaceFacebookClient
- Parameters:
code
- The device- Returns:
- An extended access token for the given
AccessToken
. - Throws:
FacebookDeviceTokenCodeExpiredException
- theDeviceCode.getCode()
is expired, please fetch a newDeviceCode
.FacebookDeviceTokenPendingException
- the user has not finished the authorisation process, yet. Please poll again later.FacebookDeviceTokenDeclinedException
- the user declined the authorisation. You have to handle this problem.FacebookDeviceTokenSlowdownException
- you tried too often to fetch the device access token. You have to use a larger interval
-
obtainUserAccessToken
public AccessToken obtainUserAccessToken(String appId, String appSecret, String redirectUri, String verificationCode) Description copied from interface:FacebookClient
Obtains an access token which can be used to perform Graph API operations on behalf of a user.See Access Tokens.
- Specified by:
obtainUserAccessToken
in interfaceFacebookClient
- Parameters:
appId
- The ID of the app for which you'd like to obtain an access token.appSecret
- The secret for the app for which you'd like to obtain an access token.redirectUri
- The redirect URI which was used to obtain theverificationCode
.verificationCode
- The verification code in the Graph API callback to the redirect URI.- Returns:
- The access token for the user identified by
appId
,appSecret
,redirectUri
andverificationCode
. - See Also:
-
obtainExtendedAccessToken
Description copied from interface:FacebookClient
Convenience method which invokesFacebookClient.obtainExtendedAccessToken(String, String, String)
with the current access token.- Specified by:
obtainExtendedAccessToken
in interfaceFacebookClient
- Parameters:
appId
- The ID of the app for which you'd like to obtain an extended access token.appSecret
- The secret for the app for which you'd like to obtain an extended access token.- Returns:
- An extended access token for the given
accessToken
. - See Also:
-
obtainRefreshedExtendedAccessToken
Description copied from interface:FacebookClient
Obtain a refreshed Instagram extended access token.This method is used to refresh an existing Instagram extended access token. Extended access tokens expire after a certain period of time, and this method allows you to obtain a new one using the refresh token provided with the original extended access token.
- Specified by:
obtainRefreshedExtendedAccessToken
in interfaceFacebookClient
- Returns:
- A new
AccessToken
object containing the refreshed access token, expiration time, and token type.
-
obtainExtendedAccessToken
Description copied from interface:FacebookClient
Obtains an extended access token for the given existing, non-expired, short-lived access_token.- Specified by:
obtainExtendedAccessToken
in interfaceFacebookClient
- Parameters:
appId
- The ID of the app for which you'd like to obtain an extended access token.appSecret
- The secret for the app for which you'd like to obtain an extended access token.accessToken
- The non-expired, short-lived access token to extend.- Returns:
- An extended access token for the given
accessToken
. - See Also:
-
getAccessTokenFromResponse
-
parseSignedRequest
Description copied from interface:FacebookClient
Parses a signed request and verifies it against your App Secret.- Specified by:
parseSignedRequest
in interfaceFacebookClient
- Type Parameters:
T
- class of objectType- Parameters:
signedRequest
- The signed request to parse.appSecret
- The secret for the app that can read this signed request.objectType
- Object type token.- Returns:
- An instance of type
objectType
which contains the decoded object embedded withinsignedRequest
.
-
urlDecodeSignedRequestToken
Decodes a component of a signed request received from Facebook using FB's special URL-encoding strategy.- Parameters:
signedRequestToken
- Token to decode.- Returns:
- The decoded token.
-
getLoginDialogUrl
public String getLoginDialogUrl(String appId, String redirectUri, ScopeBuilder scope, String state, Parameter... parameters) Description copied from interface:FacebookClient
generates the login dialog url- Specified by:
getLoginDialogUrl
in interfaceFacebookClient
- Parameters:
appId
- The ID of your app, found in your app's dashboard.redirectUri
- The URL that you want to redirect the person logging in back to. This URL will capture the response from the Login Dialog. If you are using this in a webview within a desktop app, this must be set tohttps://www.facebook.com/connect/login_success.html
.scope
- List of Permissions to request from the person using your app.state
- The state parameter is used to prevent CSRF attacks.parameters
- List of additional parameters- Returns:
- the login dialog url
-
getLoginDialogUrl
public String getLoginDialogUrl(String appId, String redirectUri, ScopeBuilder scope, Parameter... parameters) Description copied from interface:FacebookClient
generates the login dialog url- Specified by:
getLoginDialogUrl
in interfaceFacebookClient
- Parameters:
appId
- The ID of your app, found in your app's dashboard.redirectUri
- The URL that you want to redirect the person logging in back to. This URL will capture the response from the Login Dialog. If you are using this in a webview within a desktop app, this must be set tohttps://www.facebook.com/connect/login_success.html
.scope
- List of Permissions to request from the person using your app.parameters
- List of additional parameters- Returns:
- the login dialog url
-
getGenericLoginDialogUrl
protected String getGenericLoginDialogUrl(String appId, String redirectUri, ScopeBuilder scope, Supplier<String> endpointSupplier, String state, List<Parameter> parameters) -
verifySignedRequest
protected boolean verifySignedRequest(String appSecret, String algorithm, String encodedPayload, byte[] signature) Verifies that the signed request is really from Facebook.- Parameters:
appSecret
- The secret for the app that can verify this signed request.algorithm
- Signature algorithm specified by FB in the decoded payload.encodedPayload
- The encoded payload used to generate a signature for comparison against the providedsignature
.signature
- The decoded signature extracted from the signed request. Compared against a signature generated fromencodedPayload
.- Returns:
true
if the signed request is verified,false
if not.
-
debugToken
Description copied from interface:FacebookClient
When working with access tokens, you may need to check what information is associated with them, such as its user or expiry. To get this information you can use the debug tool in the developer site, or you can use this function.
You must instantiate your FacebookClient using your App Access Token, or a valid User Access Token from a developer of the app.
Note that if your app is set to Native/Desktop in the Advanced settings of your App Dashboard, the underlying GraphAPI endpoint will not work with your app token unless you change the "App Secret in Client" setting to NO. If you do not see this setting, make sure your "App Type" is set to Native/Desktop and then press the save button at the bottom of the page. This will not affect apps set to Web.
The response of the API call is a JSON array containing data and a map of fields. For example:
{ "data": { "app_id": 138483919580948, "application": "Social Cafe", "expires_at": 1352419328, "is_valid": true, "issued_at": 1347235328, "metadata": { "sso": "iphone-safari" }, "scopes": [ "email", "publish_actions" ], "user_id": 1207059 } }
Note that the
issued_at
field is not returned for short-lived access tokens.- Specified by:
debugToken
in interfaceFacebookClient
- Parameters:
inputToken
- The Access Token to debug.- Returns:
- A JsonObject containing the debug information for the accessToken.
- See Also:
-
getJsonMapper
Description copied from interface:FacebookClient
Gets theJsonMapper
used to convert Facebook JSON to Java objects.- Specified by:
getJsonMapper
in interfaceFacebookClient
- Returns:
- The
JsonMapper
used to convert Facebook JSON to Java objects. - See Also:
-
getWebRequestor
Description copied from interface:FacebookClient
Gets theWebRequestor
used to talk to the Facebook API endpoints.- Specified by:
getWebRequestor
in interfaceFacebookClient
- Returns:
- The
WebRequestor
used to talk to the Facebook API endpoints. - See Also:
-
makeRequest
Coordinates the process of executing the API request GET/POST and processing the response we receive from the endpoint.- Parameters:
endpoint
- Facebook Graph API endpoint.parameters
- Arbitrary number of parameters to send along to Facebook as part of the API call.- Returns:
- The JSON returned by Facebook for the API call.
- Throws:
FacebookException
- If an error occurs while making the Facebook API POST or processing the response.
-
makeRequest
protected String makeRequest(String endpoint, boolean executeAsPost, boolean executeAsDelete, List<BinaryAttachment> binaryAttachments, Parameter... parameters) -
makeRequest
protected String makeRequest(String endpoint, boolean executeAsPost, boolean executeAsDelete, List<BinaryAttachment> binaryAttachments, Body body, Parameter... parameters) Coordinates the process of executing the API request GET/POST and processing the response we receive from the endpoint.- Parameters:
endpoint
- Facebook Graph API endpoint.executeAsPost
-true
to execute the web request as aPOST
,false
to execute as aGET
.executeAsDelete
-true
to add a special 'treat this request as aDELETE
' parameter.binaryAttachments
- A list of binary files to include in aPOST
request. Passnull
if no attachment should be sent.parameters
- Arbitrary number of parameters to send along to Facebook as part of the API call.- Returns:
- The JSON returned by Facebook for the API call.
- Throws:
FacebookException
- If an error occurs while making the Facebook API POST or processing the response.
-
obtainAppSecretProof
Description copied from interface:FacebookClient
Generates anappsecret_proof
value.See Facebook's 'securing requests' documentation for more info.
- Specified by:
obtainAppSecretProof
in interfaceFacebookClient
- Parameters:
accessToken
- The access token required to generate theappsecret_proof
value.appSecret
- The secret for the app for which you'd like to generate theappsecret_proof
value.- Returns:
- A hex-encoded SHA256 hash as a
String
. - See Also:
-
isHttpDeleteFallback
returns if the fallback post method (true
) is used or the http delete (false
)- Returns:
true
if POST is used instead of HTTP DELETE (default)
-
setHttpDeleteFallback
Set totrue
if the facebook http delete fallback should be used. Facebook allows to use the http POST with the parameter "method=delete" to override the post and use delete instead. This feature allow http client that do not support the whole http method set, to delete objects from facebook- Parameters:
httpDeleteFallback
-true
if the http Delete Fallback is used
-
makeRequestAndProcessResponse
-
toParameterString
Generate the parameter string to be included in the Facebook API request.- Parameters:
parameters
- Arbitrary number of extra parameters to include in the request.- Returns:
- The parameter string to include in the Facebook API request.
- Throws:
FacebookJsonMappingException
- If an error occurs when building the parameter string.
-
toParameterString
Generate the parameter string to be included in the Facebook API request.- Parameters:
withJsonParameter
- add additional parameter format with type jsonparameters
- Arbitrary number of extra parameters to include in the request.- Returns:
- The parameter string to include in the Facebook API request.
- Throws:
FacebookJsonMappingException
- If an error occurs when building the parameter string.
-
createEndpointForApiCall
Given an api call (e.g. "me" or "fql.query"), returns the correct FB API endpoint to use.Useful for returning the read-only API endpoint where possible.
- Parameters:
apiCall
- The FB API call (Graph or Old REST API) for which we'd like an endpoint.hasAttachment
- Are we including a multipart file when making this API call?hasReel
- Is the binary attachment used as Facebook reel?- Returns:
- An absolute endpoint URL to communicate with.
- See Also:
-
BaseFacebookClient.createEndpointForApiCall(java.lang.String,boolean,boolean)
-
createBaseUrlForEndpoint
-
getFacebookGraphEndpointUrl
Returns the base endpoint URL for the Graph API.- Returns:
- The base endpoint URL for the Graph API.
-
getFacebookGraphVideoEndpointUrl
Returns the base endpoint URL for the Graph APIs video upload functionality.- Returns:
- The base endpoint URL for the Graph APIs video upload functionality.
- Since:
- 1.6.5
-
getFacebookReelsUploadEndpointUrl
Returns the Facebook Reels Upload endpoint URL for handling the Reels Upload- Returns:
- the Facebook Reels Upload endpoint URL
-
getFacebookEndpointUrls
-
setFacebookEndpointUrls
-
parametersWithAdditionalParameter
protected Parameter[] parametersWithAdditionalParameter(Parameter parameter, Parameter... parameters) Appends the givenparameter
to the givenparameters
array.- Parameters:
parameter
- The parameter value to append.parameters
- The parameters to which the givenparameter
is appended.- Returns:
- A new array which contains both
parameter
andparameters
.
-
urlEncodedValueForParameterName
Gets the URL-encoded version of the givenvalue
for the parameter namedname
.Includes special-case handling for access token parameters where we check if the token is already URL-encoded - if so, we don't encode again. All other parameter types are always URL-encoded.
- Parameters:
name
- The name of the parameter whose value should be URL-encoded and returned.value
- The value of the parameter which should be URL-encoded and returned.- Returns:
- The URL-encoded version of the given
value
.
-
verifyParameterLegality
Verifies that the provided parameter names don't collide with the ones we internally pass along to Facebook.- Parameters:
parameters
- The parameters to check.- Throws:
IllegalArgumentException
- If there's a parameter name collision.
-