# Class FacebookConnect

java.lang.Object
com.codename1.social.Login
com.codename1.social.FacebookConnect

public class FacebookConnect extends Login
Invokes the native bundled facebook SDK to login/logout of facebook, notice that in order for this to work server build arguments must indicate that you are using the facebook sdk! To accomplish this just define: facebook.appId=YourAppId in your build arguments. In order to obtain the app ID you need to create a native Android/iOS application and generate the right app id.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `askPublishPermissions(LoginCallback lc)`
  Asks for publish permissions, this call might suspend the application which might trigger repeated invocations of stop()/start().
  `protected Oauth2`
  `createOauth2()`
  Creates the oauth2 to be used to login in case no native login is available for this service.
  `void`
  `doLogout()`
  Logs out the current user from facebook
  `AccessToken`
  `getAccessToken()`
  The facebook token that can be used to access facebook functionality
  `static FacebookConnect`
  `getInstance()`
  Gets the FacebookConnect singleton instance .
  `String`
  `getToken()`
  The facebook token that can be used to access facebook functionality
  `boolean`
  `hasPublishPermissions()`
  Returns true if the current session already has publish permissions
  `void`
  `inviteFriends(String appLinkUrl, String previewImageUrl)`
  Opens and invite dialog to invite friends to the app https://developers.facebook.com/docs/app-invites
  `void`
  `inviteFriends(String appLinkUrl, String previewImageUrl, Callback cb)`
  Opens and invite dialog to invite friends to the app https://developers.facebook.com/docs/app-invites
  `boolean`
  `isFacebookSDKSupported()`
  Indicates whether the native platform supports native facebook login
  `boolean`
  `isInviteFriendsSupported()`
  Returns true if inviteFriends is implemented, it is supported on iOS and Android
  `boolean`
  `isLoggedIn()`
  Indicates if the user is currently logged in
  `boolean`
  `isNativeLoginSupported()`
  Returns true if this service supports native login.
  `void`
  `login()`
  Logs into facebook, notice that this call might suspend the application which might trigger repeated invocations of stop()/start() etc.
  `void`
  `logout()`
  Logs out the current user from facebook
  `boolean`
  `nativeIsLoggedIn()`
  Indicates if the user is currently logged in.
  `void`
  `nativelogin()`
  Logs in the current user natively.
  `void`
  `nativeLogout()`
  Logs out the current user natively.
  `AsyncResource<OidcTokens>`
  `signIn(String appId, String redirectUri, String... permissions)`
  Modern Facebook Login.
  `protected boolean`
  `validateToken(String token)`
  Returns true if the previous granted access token is still valid otherwise false.

  ### Methods inherited from class Login

  `addScopes, connect, doLogin, doLogin, isPreferRedirectPrompt, isUserLoggedIn, setAccessToken, setCallback, setClientId, setClientSecret, setOauth2URL, setPreferRedirectPrompt, setRedirectURI, setScope, validateToken`

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### getInstance

    public static FacebookConnect getInstance()

    Gets the FacebookConnect singleton instance .

    ###### Returns

    the FacebookConnect instance

  - ### isFacebookSDKSupported

    public boolean isFacebookSDKSupported()

    Indicates whether the native platform supports native facebook login

    ###### Returns

    true if supported

  - ### login

    public void login()

    Logs into facebook, notice that this call might suspend the application which might trigger repeated invocations of stop()/start() etc. This is due to the facebook SDK spawning a separate process to perform the login then returning to the application. Once logged in the facebook credentials will be available.

    ###### Deprecated

    use doLogin

  - ### doLogout

    public void doLogout()
    Logs out the current user from facebook
    Overrides:
      `doLogout` in class `Login`

  - ### getAccessToken

    public AccessToken getAccessToken()

    The facebook token that can be used to access facebook functionality

    ###### Returns

    the token

    Overrides:
      `getAccessToken` in class `Login`

  - ### isLoggedIn

    public boolean isLoggedIn()

    Indicates if the user is currently logged in

    ###### Returns

    true if logged in

    ###### Deprecated

    use isUserLoggedIn() instead

  - ### getToken

    public String getToken()

    The facebook token that can be used to access facebook functionality

    ###### Returns

    the token

    ###### Deprecated

    use getAccessToken instead

  - ### logout

    public void logout()

    Logs out the current user from facebook

    ###### Deprecated

    use doLogout instead

  - ### askPublishPermissions

    public void askPublishPermissions(LoginCallback lc)
    Asks for publish permissions, this call might suspend the application which might trigger repeated invocations of stop()/start().

  - ### hasPublishPermissions

    public boolean hasPublishPermissions()
    Returns true if the current session already has publish permissions

  - ### isNativeLoginSupported

    public boolean isNativeLoginSupported()
    Description copied from class: `Login`

    Returns true if this service supports native login. If implementation returns true here, the nativelogin, nativelogout, nativeIsLoggedIn should be implemented

    ###### Returns

    true if the service supports native login

    Specified by:
      `isNativeLoginSupported` in class `Login`

  - ### createOauth2

    protected Oauth2 createOauth2()
    Description copied from class: `Login`

    Creates the oauth2 to be used to login in case no native login is available for this service.

    ###### Returns

    Overrides:
      `createOauth2` in class `Login`
    Returns:
      the Oauth2 to be used to login if no native login available and on the simulator

  - ### nativelogin

    public void nativelogin()
    Description copied from class: `Login`
    Logs in the current user natively. Subclasses that uses a native sdk to login/logout should override this method.
    Overrides:
      `nativelogin` in class `Login`

  - ### nativeLogout

    public void nativeLogout()
    Description copied from class: `Login`
    Logs out the current user natively. Subclasses that uses a native sdk to login/logout should override this method.
    Overrides:
      `nativeLogout` in class `Login`

  - ### nativeIsLoggedIn

    public boolean nativeIsLoggedIn()
    Description copied from class: `Login`

    Indicates if the user is currently logged in. Subclasses that uses a native sdk to login/logout should override this method.

    ###### Returns

    true if logged in

    Overrides:
      `nativeIsLoggedIn` in class `Login`

  - ### inviteFriends

    public void inviteFriends(String appLinkUrl, String previewImageUrl)

    Opens and invite dialog to invite friends to the app https://developers.facebook.com/docs/app-invites

    ###### Parameters

    - `appLinkUrl`: @param appLinkUrl App Link for what should be opened when the recipient clicks on the install/play button on the app invite page.

    - `previewImageUrl`: url to an image to be used in the invite, can be null

    ###### Deprecated

    The Facebook SDK no longer supports app invites. https://developers.facebook.com/blog/post/2017/11/07/changes-developer-offerings/

  - ### inviteFriends

    public void inviteFriends(String appLinkUrl, String previewImageUrl, Callback cb)

    Opens and invite dialog to invite friends to the app https://developers.facebook.com/docs/app-invites

    ###### Parameters

    - `appLinkUrl`: @param appLinkUrl App Link for what should be opened when the recipient clicks on the install/play button on the app invite page.

    - `previewImageUrl`: url to an image to be used in the invite, can be null

    - `cb`: @param cb a Callback to be used when we need to know if the Facebook invite was successful. If the invite was successful the onSucess method will be called If the user canceled the onError method will be called with error code -1. If an error occurred the onError method will be called with error code 0.

    ###### Deprecated

    The Facebook SDK no longer supports app invites https://developers.facebook.com/blog/post/2017/11/07/changes-developer-offerings/

  - ### signIn

    public AsyncResource<OidcTokens> signIn(String appId, String redirectUri, String... permissions)

    Modern Facebook Login. Goes through Facebook's OAuth 2.0 endpoints via the system browser (`SystemBrowser`), independent of the native Facebook SDK. Use this method for browser-based and cross-platform consistency; the older `Login.doLogin()` path remains for code that depends on the iOS/Android Facebook SDK integration.

    ###### Parameters

    - `appId`: Facebook App ID.
    - `redirectUri`: Must match a Valid OAuth Redirect URI configured in the app dashboard.
    - `permissions`: Facebook permissions (`public_profile`, `email`, ...). Defaults to `public_profile email` when empty.

    ###### Returns

    An `AsyncResource` resolving to the granted access token wrapped in `OidcTokens` (note: Facebook does not issue OIDC ID tokens for classic OAuth flows -- `getIdToken()` will be `null`; use `getAccessToken()` and call the Graph API to read user profile data).

    ###### Since

    8.0

  - ### isInviteFriendsSupported

    public boolean isInviteFriendsSupported()

    Returns true if inviteFriends is implemented, it is supported on iOS and Android

    NOTE: Since updating to Facebook SDK 5.6.0 (April 1, 2020), invite friends is no longer supported on iOS. It will eventually be removed from Android as well, as Facebook no longer supports App invites in its native SDKs.

    ###### Returns

    true if inviteFriends is implemented

  - ### validateToken

    protected boolean validateToken(String token)
    Description copied from class: `Login`

    Returns true if the previous granted access token is still valid otherwise false.

    ###### Parameters

    - `token`: the access token to check

    ###### Returns

    true of the token is valid

    Specified by:
      `validateToken` in class `Login`