001/*
002 * Copyright (c) 2010-2026 Mark Allen, Norbert Bartels.
003 *
004 * Permission is hereby granted, free of charge, to any person obtaining a copy
005 * of this software and associated documentation files (the "Software"), to deal
006 * in the Software without restriction, including without limitation the rights
007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008 * copies of the Software, and to permit persons to whom the Software is
009 * furnished to do so, subject to the following conditions:
010 *
011 * The above copyright notice and this permission notice shall be included in
012 * all copies or substantial portions of the Software.
013 *
014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
020 * THE SOFTWARE.
021 */
022package com.restfb;
023
024import java.util.List;
025import java.util.Map;
026
027import com.restfb.batch.BatchRequest;
028import com.restfb.batch.BatchResponse;
029import com.restfb.exception.*;
030import com.restfb.exception.devicetoken.FacebookDeviceTokenCodeExpiredException;
031import com.restfb.exception.devicetoken.FacebookDeviceTokenDeclinedException;
032import com.restfb.exception.devicetoken.FacebookDeviceTokenPendingException;
033import com.restfb.exception.devicetoken.FacebookDeviceTokenSlowdownException;
034import com.restfb.scope.ScopeBuilder;
035import com.restfb.types.DebugTokenInfo;
036import com.restfb.types.DeviceCode;
037
038/**
039 * Specifies how a <a href="http://developers.facebook.com/docs/api">Facebook Graph API</a> client must operate.
040 * <p>
041 * If you'd like to...
042 *
043 * <ul>
044 * <li>Fetch an object: use {@link #fetchObject(String, Class, Parameter...)} or
045 * {@link #fetchObjects(List, Class, Parameter...)}</li>
046 * <li>Fetch a connection: use {@link #fetchConnection(String, Class, Parameter...)}</li>
047 * <li>Execute operations in batch: use {@link #executeBatch(BatchRequest...)} or {@link #executeBatch(List, List)}</li>
048 * <li>Publish data: use {@link #publish(String, Class, Parameter...)} or
049 * {@link #publish(String, Class, BinaryAttachment, Parameter...)}</li>
050 * <li>Delete an object: use {@link #deleteObject(String, Parameter...)}</li>
051 * </ul>
052 *
053 * <p>
054 * You may also perform some common access token operations. If you'd like to...
055 *
056 * <ul>
057 * <li>Extend the life of an access token: use {@link #obtainExtendedAccessToken(String, String, String)}</li>
058 * <li>Obtain an access token for use on behalf of an application instead of a user, use
059 * {@link #obtainAppAccessToken(String, String)}.</li>
060 * <li>Convert old-style session keys to OAuth access tokens: use
061 * {@link #convertSessionKeysToAccessTokens(String, String, String...)}</li>
062 * <li>Verify and extract data from a signed request: use {@link #parseSignedRequest(String, String, Class)}</li>
063 * </ul>
064 *
065 * @author <a href="http://restfb.com">Mark Allen</a>
066 * @author Scott Hernandez
067 * @author Mattia Tommasone
068 * @author <a href="http://ex-nerd.com">Chris Petersen</a>
069 * @author Josef Gierbl
070 * @author Broc Seib
071 */
072public interface FacebookClient {
073  /**
074   * Fetches a single <a href="http://developers.facebook.com/docs/reference/api/">Graph API object</a>, mapping the
075   * result to an instance of {@code objectType}.
076   *
077   * @param <T>
078   *          Java type to map to.
079   * @param object
080   *          ID of the object to fetch, e.g. {@code "me"}.
081   * @param objectType
082   *          Object type token.
083   * @param parameters
084   *          URL parameters to include in the API call (optional).
085   * @return An instance of type {@code objectType} which contains the requested object's data.
086   * @throws FacebookException
087   *           If an error occurs while performing the API call.
088   */
089  <T> T fetchObject(String object, Class<T> objectType, Parameter... parameters);
090
091  /**
092   * Variant of {@link #fetchObject(String, Class, Parameter...)} that additionally exposes response metadata (debug
093   * headers, raw headers, HTTP method, request URL, and duration) in an {@link ApiResult} wrapper.
094   *
095   * @param <T>
096   *          Java type to map to.
097   * @param object
098   *          ID of the object to fetch, e.g. {@code "me"}.
099   * @param objectType
100   *          Object type token.
101   * @param parameters
102   *          URL parameters to include in the API call (optional).
103   * @return ApiResult containing the mapped object plus response metadata.
104   * @throws FacebookException
105   *           If an error occurs while performing the API call.
106   * @since 2026.0.0
107   */
108  default <T> ApiResult<T> fetchObjectWithResult(String object, Class<T> objectType, Parameter... parameters) {
109    return ApiResult.withoutMetadata(fetchObject(object, objectType, parameters));
110  }
111
112  /**
113   * creates a new <code>FacebookClient</code> from an old one.
114   * <p>
115   * App secret and api version are taken from the original client.
116   *
117   * @param accessToken
118   *          this accesstoken is used for the new client
119   * @return a new Facebookclient
120   */
121  FacebookClient createClientWithAccessToken(String accessToken);
122
123  /**
124   * Fetches up to 50 <a href="http://developers.facebook.com/docs/reference/api/">Graph API objects</a> in a single
125   * batch call, mapping the results to an instance of {@code objectType}.
126   * <p>
127   * You'll need to write your own container type ({@code objectType}) to hold the results. See
128   * <a href="http://restfb.com">http://restfb.com</a> for an example of how to do this.
129   *
130   * @param <T>
131   *          Java type to map to.
132   * @param ids
133   *          IDs of the objects to fetch, e.g. {@code "me", "arjun"}.
134   * @param objectType
135   *          Object type token.
136   * @param parameters
137   *          URL parameters to include in the API call (optional).
138   * @return An instance of type {@code objectType} which contains the requested objects' data.
139   * @throws FacebookException
140   *           If an error occurs while performing the API call.
141   * @throws IllegalArgumentException
142   *           If more than 50 IDs are provided.
143   */
144  <T> T fetchObjects(List<String> ids, Class<T> objectType, Parameter... parameters);
145
146  /**
147   * Variant of {@link #fetchObjects(List, Class, Parameter...)} that exposes response metadata in an {@link ApiResult}
148   * wrapper.
149   *
150   * @param <T>
151   *          Java type to map to.
152   * @param ids
153   *          IDs of the objects to fetch.
154   * @param objectType
155   *          Object type token.
156   * @param parameters
157   *          URL parameters to include in the API call (optional).
158   * @return ApiResult containing the mapped objects plus response metadata.
159   * @throws FacebookException
160   *           If an error occurs while performing the API call.
161   * @throws IllegalArgumentException
162   *           If more than 50 IDs are provided.
163   * @since 2026.0.0
164   */
165  default <T> ApiResult<T> fetchObjectsWithResult(List<String> ids, Class<T> objectType, Parameter... parameters) {
166    return ApiResult.withoutMetadata(fetchObjects(ids, objectType, parameters));
167  }
168
169  /**
170   * Fetches a Graph API {@code Connection} type, mapping the result to an instance of {@code connectionType}.
171   *
172   * @param <T>
173   *          Java type to map to.
174   * @param connection
175   *          The name of the connection, e.g. {@code "me/feed"}.
176   * @param connectionType
177   *          Connection type token.
178   * @param parameters
179   *          URL parameters to include in the API call (optional).
180   * @return An instance of type {@code connectionType} which contains the requested Connection's data. Metadata about
181   *         the HTTP response can be accessed via {@link Connection#getResponseMetadata()}.
182   * @throws FacebookException
183   *           If an error occurs while performing the API call.
184   */
185  <T> Connection<T> fetchConnection(String connection, Class<T> connectionType, Parameter... parameters);
186
187  /**
188   * Fetches a previous/next page of a Graph API {@code Connection} type, mapping the result to an instance of
189   * {@code connectionType}.
190   *
191   * @param <T>
192   *          Java type to map to.
193   * @param connectionPageUrl
194   *          The URL of the connection page to fetch, usually retrieved via {@link Connection#getPreviousPageUrl()} or
195   *          {@link Connection#getNextPageUrl()}.
196   * @param connectionType
197   *          Connection type token.
198   * @return An instance of type {@code connectionType} which contains the requested Connection's data. Metadata about
199   *         the HTTP response can be accessed via {@link Connection#getResponseMetadata()}.
200   * @throws FacebookException
201   *           If an error occurs while performing the API call.
202   */
203  <T> Connection<T> fetchConnectionPage(String connectionPageUrl, Class<T> connectionType);
204
205  /**
206   * Factory method to create a {@link Connection} instance from raw JSON.
207   *
208   * @param connectionJson
209   *          raw JSON response data for the connection
210   * @param connectionType
211   *          Java type of the elements contained in the connection
212   * @param <T>
213   *          element type
214   * @return a new {@link Connection} based on the provided payload
215   * @since 2026.1.0
216   */
217  default <T> Connection<T> createConnection(String connectionJson, Class<T> connectionType) {
218    return new Connection<>(this, connectionJson, connectionType);
219  }
220
221  /**
222   * Executes operations as a batch using the <a href="https://developers.facebook.com/docs/reference/api/batch/">Batch
223   * API</a>.
224   *
225   * @param batchRequests
226   *          The operations to execute.
227   * @return The execution results in the order in which the requests were specified.
228   */
229  List<BatchResponse> executeBatch(BatchRequest... batchRequests);
230
231  /**
232   * Executes operations as a batch using the <a href="https://developers.facebook.com/docs/reference/api/batch/">Batch
233   * API</a>.
234   *
235   * @param batchRequests
236   *          The operations to execute.
237   * @return The execution results in the order in which the requests were specified.
238   */
239  List<BatchResponse> executeBatch(List<BatchRequest> batchRequests);
240
241  /**
242   * Executes operations as a batch with binary attachments using the
243   * <a href="https://developers.facebook.com/docs/reference/api/batch/">Batch API</a>.
244   *
245   * @param batchRequests
246   *          The operations to execute.
247   * @param binaryAttachments
248   *          Binary attachments referenced by the batch requests.
249   * @return The execution results in the order in which the requests were specified.
250   * @since 1.6.5
251   */
252  List<BatchResponse> executeBatch(List<BatchRequest> batchRequests, List<BinaryAttachment> binaryAttachments);
253
254  /**
255   * Performs a <a href="http://developers.facebook.com/docs/api#publishing">Graph API publish</a> operation on the
256   * given {@code connection}, mapping the result to an instance of {@code objectType}.
257   *
258   * @param <T>
259   *          Java type to map to.
260   * @param connection
261   *          The Connection to publish to.
262   * @param objectType
263   *          Object type token.
264   * @param parameters
265   *          URL parameters to include in the API call.
266   * @return An instance of type {@code objectType} which contains the Facebook response to your publish request.
267   * @throws FacebookException
268   *           If an error occurs while performing the API call.
269   */
270  <T> T publish(String connection, Class<T> objectType, Parameter... parameters);
271
272  /**
273   * Variant of {@link #publish(String, Class, Parameter...)} that additionally exposes response metadata.
274   *
275   * @param <T>
276   *          Java type to map to.
277   * @param connection
278   *          The Connection to publish to.
279   * @param objectType
280   *          Object type token.
281   * @param parameters
282   *          URL parameters to include in the API call.
283   * @return ApiResult containing the publish response plus metadata.
284   * @throws FacebookException
285   *           If an error occurs while performing the API call.
286   * @since 2026.0.0
287   */
288  default <T> ApiResult<T> publishWithResult(String connection, Class<T> objectType, Parameter... parameters) {
289    return ApiResult.withoutMetadata(publish(connection, objectType, parameters));
290  }
291
292  /**
293   * Performs a <a href="http://developers.facebook.com/docs/api#publishing">Graph API publish</a> operation on the
294   * given {@code connection} and includes some files - photos, for example - in the publish request, and mapping the
295   * result to an instance of {@code objectType}.
296   *
297   * @param <T>
298   *          Java type to map to.
299   * @param connection
300   *          The Connection to publish to.
301   * @param objectType
302   *          Object type token.
303   * @param binaryAttachments
304   *          The files to include in the publish request.
305   * @param parameters
306   *          URL parameters to include in the API call.
307   * @return An instance of type {@code objectType} which contains the Facebook response to your publish request.
308   * @throws FacebookException
309   *           If an error occurs while performing the API call.
310   */
311  <T> T publish(String connection, Class<T> objectType, List<BinaryAttachment> binaryAttachments,
312      Parameter... parameters);
313
314  /**
315   * Variant of {@link #publish(String, Class, List, Parameter...)} that additionally exposes response metadata.
316   *
317   * @param <T>
318   *          Java type to map to.
319   * @param connection
320   *          The Connection to publish to.
321   * @param objectType
322   *          Object type token.
323   * @param binaryAttachments
324   *          The files to include in the publish request.
325   * @param parameters
326   *          URL parameters to include in the API call.
327   * @return ApiResult containing the publish response plus metadata.
328   * @throws FacebookException
329   *           If an error occurs while performing the API call.
330   * @since 2026.0.0
331   */
332  default <T> ApiResult<T> publishWithResult(String connection, Class<T> objectType,
333      List<BinaryAttachment> binaryAttachments, Parameter... parameters) {
334    return ApiResult.withoutMetadata(publish(connection, objectType, binaryAttachments, parameters));
335  }
336
337  /**
338   * Performs a <a href="http://developers.facebook.com/docs/api#publishing">Graph API publish</a> operation on the
339   * given {@code connection} and includes a file - a photo, for example - in the publish request, and mapping the
340   * result to an instance of {@code objectType}.
341   *
342   * @param <T>
343   *          Java type to map to.
344   * @param connection
345   *          The Connection to publish to.
346   * @param objectType
347   *          Object type token.
348   * @param binaryAttachment
349   *          The file to include in the publish request.
350   * @param parameters
351   *          URL parameters to include in the API call.
352   * @return An instance of type {@code objectType} which contains the Facebook response to your publish request.
353   * @throws FacebookException
354   *           If an error occurs while performing the API call.
355   */
356  <T> T publish(String connection, Class<T> objectType, BinaryAttachment binaryAttachment, Parameter... parameters);
357
358  /**
359   * Variant of {@link #publish(String, Class, BinaryAttachment, Parameter...)} that additionally exposes response
360   * metadata.
361   *
362   * @param <T>
363   *          Java type to map to.
364   * @param connection
365   *          The Connection to publish to.
366   * @param objectType
367   *          Object type token.
368   * @param binaryAttachment
369   *          The file to include in the publish request.
370   * @param parameters
371   *          URL parameters to include in the API call.
372   * @return ApiResult containing the publish response plus metadata.
373   * @throws FacebookException
374   *           If an error occurs while performing the API call.
375   * @since 2026.0.0
376   */
377  default <T> ApiResult<T> publishWithResult(String connection, Class<T> objectType, BinaryAttachment binaryAttachment,
378      Parameter... parameters) {
379    return ApiResult.withoutMetadata(publish(connection, objectType, binaryAttachment, parameters));
380  }
381
382  /**
383   * Performs a <a href="http://developers.facebook.com/docs/api#publishing">Graph API publish</a> operation on the
384   * given {@code connection} and includes special body in the publish request, and mapping the result to an instance of
385   * {@code objectType}.
386   *
387   * @param <T>
388   *          Java type to map to.
389   * @param connection
390   *          The Connection to publish to.
391   * @param objectType
392   *          Object type token.
393   * @param body
394   *          The body used in the POST request.
395   * @param parameters
396   *          URL parameters to include in the API call.
397   * @return An instance of type {@code objectType} which contains the Facebook response to your publish request.
398   * @throws FacebookException
399   *           If an error occurs while performing the API call.
400   */
401  <T> T publish(String connection, Class<T> objectType, Body body, Parameter... parameters);
402
403  /**
404   * Variant of {@link #publish(String, Class, Body, Parameter...)} that additionally exposes response metadata.
405   *
406   * @param <T>
407   *          Java type to map to.
408   * @param connection
409   *          The Connection to publish to.
410   * @param objectType
411   *          Object type token.
412   * @param body
413   *          The body used in the POST request.
414   * @param parameters
415   *          URL parameters to include in the API call.
416   * @return ApiResult containing the publish response plus metadata.
417   * @throws FacebookException
418   *           If an error occurs while performing the API call.
419   * @since 2026.0.0
420   */
421  default <T> ApiResult<T> publishWithResult(String connection, Class<T> objectType, Body body,
422      Parameter... parameters) {
423    return ApiResult.withoutMetadata(publish(connection, objectType, body, parameters));
424  }
425
426  /**
427   * Performs a <a href="http://developers.facebook.com/docs/api#deleting">Graph API delete</a> operation on the given
428   * {@code object}.
429   *
430   * @param object
431   *          The ID of the object to delete.
432   * @param parameters
433   *          URL parameters to include in the API call.
434   * @return {@code true} if Facebook indicated that the object was successfully deleted, {@code false} otherwise.
435   * @throws FacebookException
436   *           If an error occurred while attempting to delete the object.
437   */
438  boolean deleteObject(String object, Parameter... parameters);
439
440  /**
441   * Variant of {@link #deleteObject(String, Parameter...)} that additionally exposes response metadata.
442   *
443   * @param object
444   *          The ID of the object to delete.
445   * @param parameters
446   *          URL parameters to include in the API call.
447   * @return ApiResult containing the delete success flag plus metadata.
448   * @throws FacebookException
449   *           If an error occurred while attempting to delete the object.
450   * @since 2026.0.0
451   */
452  default ApiResult<Boolean> deleteObjectWithResult(String object, Parameter... parameters) {
453    return ApiResult.withoutMetadata(deleteObject(object, parameters));
454  }
455
456  /**
457   * Converts an arbitrary number of {@code sessionKeys} to OAuth access tokens.
458   * <p>
459   * See the <a href="http://developers.facebook.com/docs/guides/upgrade">Facebook Platform Upgrade Guide</a> for
460   * details on how this process works and why you should convert your application's session keys if you haven't
461   * already.
462   *
463   * @param appId
464   *          A Facebook application ID.
465   * @param secretKey
466   *          A Facebook application secret key.
467   * @param sessionKeys
468   *          The Old REST API session keys to be converted to OAuth access tokens.
469   * @return A list of access tokens ordered to correspond to the {@code sessionKeys} argument list.
470   * @throws FacebookException
471   *           If an error occurs while attempting to convert the session keys to API keys.
472   * @since 1.6
473   */
474  List<AccessToken> convertSessionKeysToAccessTokens(String appId, String secretKey, String... sessionKeys);
475
476  /**
477   * Obtains an access token which can be used to perform Graph API operations on behalf of a user.
478   * <p>
479   * See <a href="https://developers.facebook.com/docs/facebook-login/access-tokens">Access Tokens</a>.
480   *
481   * @param appId
482   *          The ID of the app for which you'd like to obtain an access token.
483   * @param appSecret
484   *          The secret for the app for which you'd like to obtain an access token.
485   * @param redirectUri
486   *          The redirect URI which was used to obtain the {@code verificationCode}.
487   * @param verificationCode
488   *          The verification code in the Graph API callback to the redirect URI.
489   * @return The access token for the user identified by {@code appId}, {@code appSecret}, {@code redirectUri} and
490   *         {@code verificationCode}.
491   * @throws FacebookException
492   *           If an error occurs while attempting to obtain an access token.
493   * @since 1.8.0
494   */
495  AccessToken obtainUserAccessToken(String appId, String appSecret, String redirectUri, String verificationCode);
496
497  /**
498   * Obtains an access token which can be used to perform Graph API operations on behalf of an application instead of a
499   * user.
500   * <p>
501   * See <a href="https://developers.facebook.com/docs/authentication/applications/" >Facebook's authenticating as an
502   * app documentation</a>.
503   *
504   * @param appId
505   *          The ID of the app for which you'd like to obtain an access token.
506   * @param appSecret
507   *          The secret for the app for which you'd like to obtain an access token.
508   * @return The access token for the application identified by {@code appId} and {@code appSecret}.
509   * @throws FacebookException
510   *           If an error occurs while attempting to obtain an access token.
511   * @since 1.6.10
512   */
513  AccessToken obtainAppAccessToken(String appId, String appSecret);
514
515  /**
516   * Obtains an extended access token for the given existing, non-expired, short-lived access_token.
517   * <p>
518   * See <a href="https://developers.facebook.com/roadmap/offline-access-removal/#extend_token">Facebook's extend access
519   * token documentation</a>.
520   *
521   * @param appId
522   *          The ID of the app for which you'd like to obtain an extended access token.
523   * @param appSecret
524   *          The secret for the app for which you'd like to obtain an extended access token.
525   * @param accessToken
526   *          The non-expired, short-lived access token to extend.
527   * @return An extended access token for the given {@code accessToken}.
528   * @throws FacebookException
529   *           If an error occurs while attempting to obtain an extended access token.
530   * @since 1.6.10
531   */
532  AccessToken obtainExtendedAccessToken(String appId, String appSecret, String accessToken);
533
534  /**
535   * Generates an {@code appsecret_proof} value.
536   * <p>
537   * See <a href="https://developers.facebook.com/docs/graph-api/securing-requests">Facebook's 'securing requests'
538   * documentation</a> for more info.
539   *
540   * @param accessToken
541   *          The access token required to generate the {@code appsecret_proof} value.
542   * @param appSecret
543   *          The secret for the app for which you'd like to generate the {@code appsecret_proof} value.
544   * @return A hex-encoded SHA256 hash as a {@code String}.
545   * @throws IllegalStateException
546   *           If creating the {@code appsecret_proof} fails.
547   * @since 1.6.13
548   */
549  String obtainAppSecretProof(String accessToken, String appSecret);
550
551  /**
552   * Convenience method which invokes {@link #obtainExtendedAccessToken(String, String, String)} with the current access
553   * token.
554   *
555   * @param appId
556   *          The ID of the app for which you'd like to obtain an extended access token.
557   * @param appSecret
558   *          The secret for the app for which you'd like to obtain an extended access token.
559   * @return An extended access token for the given {@code accessToken}.
560   * @throws FacebookException
561   *           If an error occurs while attempting to obtain an extended access token.
562   * @throws IllegalStateException
563   *           If this instance was not constructed with an access token.
564   * @since 1.6.10
565   */
566  AccessToken obtainExtendedAccessToken(String appId, String appSecret);
567
568  /**
569   * Obtain a refreshed Instagram extended access token.
570   *
571   * <p>
572   * This method is used to refresh an existing Instagram extended access token. Extended access tokens expire after a
573   * certain period of time, and this method allows you to obtain a new one using the refresh token provided with the
574   * original extended access token.
575   *
576   * @return A new {@link AccessToken} object containing the refreshed access token, expiration time, and token type.
577   * @throws FacebookResponseContentException
578   *           If the response from the Facebook API cannot be parsed or if the access token cannot be extracted from
579   *           the response.
580   */
581  AccessToken obtainRefreshedExtendedAccessToken();
582
583  /**
584   * Parses a signed request and verifies it against your App Secret.
585   * <p>
586   * See <a href="http://developers.facebook.com/docs/howtos/login/signed-request/">Facebook's signed request
587   * documentation</a>.
588   *
589   * @param signedRequest
590   *          The signed request to parse.
591   * @param appSecret
592   *          The secret for the app that can read this signed request.
593   * @param objectType
594   *          Object type token.
595   * @param <T>
596   *          class of objectType
597   * @return An instance of type {@code objectType} which contains the decoded object embedded within
598   *         {@code signedRequest}.
599   * @throws FacebookSignedRequestParsingException
600   *           If an error occurs while trying to process {@code signedRequest}.
601   * @throws FacebookSignedRequestVerificationException
602   *           If {@code signedRequest} fails verification against {@code appSecret}.
603   * @since 1.6.13
604   */
605  <T> T parseSignedRequest(String signedRequest, String appSecret, Class<T> objectType);
606
607  /**
608   * Method to initialize the device access token generation.
609   * <p>
610   * You receive a {@link DeviceCode} instance and have to show the user the {@link DeviceCode#getVerificationUri()} and
611   * the {@link DeviceCode#getUserCode()}. The user have to enter the user code at the verification url.
612   * <p>
613   * Save the {@link DeviceCode#getCode()} to use it later, when polling Facebook with the
614   * {@link #obtainDeviceAccessToken(java.lang.String)} method.
615   *
616   * @param scope
617   *          List of Permissions to request from the person using your app.
618   * @return Instance of {@code DeviceCode} including the information to obtain the Device access token
619   */
620  DeviceCode fetchDeviceCode(ScopeBuilder scope);
621
622  /**
623   * Method to poll Facebook and fetch the Device Access Token.
624   * <p>
625   * You have to use this method to check if the user confirms the authorization.
626   * <p>
627   * {@link FacebookOAuthException} can be thrown if the authorization is declined or still pending.
628   *
629   * @param code
630   *          The device
631   * @return An extended access token for the given {@link AccessToken}.
632   * @throws com.restfb.exception.devicetoken.FacebookDeviceTokenCodeExpiredException
633   *           the {@link DeviceCode#getCode()} is expired, please fetch a new {@link DeviceCode}.
634   * @throws com.restfb.exception.devicetoken.FacebookDeviceTokenPendingException
635   *           the user has not finished the authorisation process, yet. Please poll again later.
636   * @throws com.restfb.exception.devicetoken.FacebookDeviceTokenDeclinedException
637   *           the user declined the authorisation. You have to handle this problem.
638   * @throws com.restfb.exception.devicetoken.FacebookDeviceTokenSlowdownException
639   *           you tried too often to fetch the device access token. You have to use a larger interval
640   * @since 1.12.0
641   */
642  AccessToken obtainDeviceAccessToken(String code) throws FacebookDeviceTokenCodeExpiredException,
643      FacebookDeviceTokenPendingException, FacebookDeviceTokenDeclinedException, FacebookDeviceTokenSlowdownException;
644
645  /**
646   * <p>
647   * When working with access tokens, you may need to check what information is associated with them, such as its user
648   * or expiry. To get this information you can use the debug tool in the developer site, or you can use this function.
649   * </p>
650   *
651   * <p>
652   * You must instantiate your FacebookClient using your App Access Token, or a valid User Access Token from a developer
653   * of the app.
654   * </p>
655   *
656   * <p>
657   * Note that if your app is set to Native/Desktop in the Advanced settings of your App Dashboard, the underlying
658   * GraphAPI endpoint will not work with your app token unless you change the "App Secret in Client" setting to NO. If
659   * you do not see this setting, make sure your "App Type" is set to Native/Desktop and then press the save button at
660   * the bottom of the page. This will not affect apps set to Web.
661   * </p>
662   *
663   * <p>
664   * The response of the API call is a JSON array containing data and a map of fields. For example:
665   * </p>
666   *
667   * <pre> {@code { "data": { "app_id": 138483919580948, "application": "Social Cafe", "expires_at": 1352419328,
668   * "is_valid": true, "issued_at": 1347235328, "metadata": { "sso": "iphone-safari" }, "scopes": [ "email",
669   * "publish_actions" ], "user_id": 1207059 } } } </pre>
670   *
671   * <p>
672   * Note that the {@code issued_at} field is not returned for short-lived access tokens.
673   * </p>
674   *
675   * <p>
676   * See <a href="https://developers.facebook.com/docs/howtos/login/debugging-access-tokens/"> Debugging an Access
677   * Token</a>
678   * </p>
679   *
680   * @param inputToken
681   *          The Access Token to debug.
682   *
683   * @return A JsonObject containing the debug information for the accessToken. @since 1.6.13
684   */
685  DebugTokenInfo debugToken(String inputToken);
686
687  /**
688   * Gets the {@code JsonMapper} used to convert Facebook JSON to Java objects.
689   *
690   * @return The {@code JsonMapper} used to convert Facebook JSON to Java objects.
691   * @since 1.6.7
692   */
693  JsonMapper getJsonMapper();
694
695  /**
696   * Gets the {@code WebRequestor} used to talk to the Facebook API endpoints.
697   *
698   * @return The {@code WebRequestor} used to talk to the Facebook API endpoints.
699   * @since 1.6.7
700   */
701  WebRequestor getWebRequestor();
702
703  /**
704   * generates an logout url
705   *
706   * @param next
707   *          may be null, url the webpage should redirect after logout
708   * @return the logout url
709   * @since 1.9.0
710   */
711  String getLogoutUrl(String next);
712
713  /**
714   * generates the login dialog url
715   *
716   * @param appId
717   *          The ID of your app, found in your app's dashboard.
718   * @param redirectUri
719   *          The URL that you want to redirect the person logging in back to. This URL will capture the response from
720   *          the Login Dialog. If you are using this in a webview within a desktop app, this must be set to
721   *          <code>https://www.facebook.com/connect/login_success.html</code>.
722   * @param scope
723   *          List of Permissions to request from the person using your app.
724   * @param state
725   *          The state parameter is used to prevent CSRF attacks.
726   * @param parameters
727   *          List of additional parameters
728   * @since 1.9.0
729   * @return the login dialog url
730   */
731  String getLoginDialogUrl(String appId, String redirectUri, ScopeBuilder scope, String state, Parameter... parameters);
732
733  /**
734   * generates the login dialog url
735   *
736   * @param appId
737   *          The ID of your app, found in your app's dashboard.
738   * @param redirectUri
739   *          The URL that you want to redirect the person logging in back to. This URL will capture the response from
740   *          the Login Dialog. If you are using this in a webview within a desktop app, this must be set to
741   *          <code>https://www.facebook.com/connect/login_success.html</code>.
742   * @param scope
743   *          List of Permissions to request from the person using your app.
744   * @param additionalParameters
745   *          List of additional parameters
746   * @since 1.9.0
747   * @return the login dialog url
748   */
749  String getLoginDialogUrl(String appId, String redirectUri, ScopeBuilder scope, Parameter... additionalParameters);
750
751  /**
752   * Generates the login dialog url for Business
753   *
754   * @param appId
755   *          The ID of your app, found in your app's dashboard.
756   * @param redirectUri
757   *          The URL that you want to redirect the person logging in back to. This URL will capture the response from
758   *          the Login Dialog. If you are using this in a webview within a desktop app, this must be set to
759   *          <code>https://www.facebook.com/connect/login_success.html</code>.
760   * @param configId
761   *          The configuration ID that defines the permissions and settings, found in the product section of your app's
762   *          dashboard.
763   * @param state
764   *          An optional string used to maintain state between the request and the callback.
765   * @param parameters
766   *          List of additional parameters
767   * @return the login dialog url
768   */
769  String getBusinessLoginDialogUrl(String appId, String redirectUri, String configId, String state,
770      Parameter... parameters);
771
772  default boolean isAppSecretProofWithTime() {
773    return false;
774  }
775}