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
    Asks for publish permissions, this call might suspend the application which might trigger repeated invocations of stop()/start().
    protected Oauth2
    Creates the oauth2 to be used to login in case no native login is available for this service.
    void
    Logs out the current user from facebook
    The facebook token that can be used to access facebook functionality
    Gets the FacebookConnect singleton instance .
    The facebook token that can be used to access facebook functionality
    boolean
    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
    Indicates whether the native platform supports native facebook login
    boolean
    Returns true if inviteFriends is implemented, it is supported on iOS and Android
    boolean
    Indicates if the user is currently logged in
    boolean
    Returns true if this service supports native login.
    void
    Logs into facebook, notice that this call might suspend the application which might trigger repeated invocations of stop()/start() etc.
    void
    Logs out the current user from facebook
    boolean
    Indicates if the user is currently logged in.
    void
    Logs in the current user natively.
    void
    Logs out the current user natively.
    protected boolean
    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
    Modifier and Type
    Method
    Description
    addScopes(String... scopes)
    Adds the given scopes to the OAuth2 login request.
    Connects to the login service asynchronously, automatically logging in if not yet logged in.
    void
    Logs in the user.
    void
    Initiates login using the given single-use callback.
    boolean
    A flag used by the javascript port to indicate that the login will use a redirect for the prompt instead of a popup.
    boolean
    Indicates if the user is currently logged in
    void
    Sets the Login access token
    void
    Sets the login callback that will receive event callback notification from the API
    void
    The client id (appid) which asks to connect
    void
    The client secret
    void
    setOauth2URL(String oauth2URL)
    The oauth2 URL
    void
    setPreferRedirectPrompt(boolean preferRedirectPrompt)
    A flag used by the javascript port to indicate that the login will use a redirect for the prompt instead of a popup.
    void
    setRedirectURI(String redirectURI)
    The redirect URI
    void
    The authentication scope
    void
    This method tries to validate the last access token if exists, if the last token is not valid anymore it will try to login the user in order to get a fresh token The method blocks until a valid token has been granted

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    Modifier and Type
    Method
    Description
    protected Object
     
    boolean
    Indicates whether some other object is "equal to" this one.
    final Class
    Returns the runtime class of an object.
    int
    Returns a hash code value for the object.
    final void
    Wakes up a single thread that is waiting on this object's monitor.
    final void
    Wakes up all threads that are waiting on this object's monitor.
    Returns a string representation of the object.
    final void
    Causes current thread to wait until another thread invokes the method or the method for this object.
    final void
    wait(long timeout)
    Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.
    final void
    wait(long timeout, int nanos)
    Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
  • 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/

    • 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