Skip to content

Login with Twitter

To enable Twitter account log in to your Backendless application:

  1. Create your application at https://apps.twitter.com/.
  2. In the application's Settings tab, set the Website and Callback URL to https://api.backendless.com
  3. From the Keys and Access Tokens tab, copy the Consumer Key and the Consumer Secret values.
  4. Click the Permissions tab and select the Request email addresses from users checkbox. Click Update Settings.
  5. Log in to your account in the Backendless Console, select your app and click Manage.
  6. Scroll down to the Social Settings section and insert the values copied on step 4 into the Twitter Consumer key and Twitter Consumer secret fields.

Use following code to allow the users to log in to your application with their Twitter account:

Backendless.UserService.loginWithTwitter( MainActivity.this, new AsyncCallback<BackendlessUser>() 
{ 
  @Override 
  public void handleResponse( BackendlessUser loggedInUser ) 
  { 
    // user logged in successfully
  } 

  @Override 
  public void handleFault( BackendlessFault fault ) 
  { 
    // failed to log in
  } 
} );

Add the fields mapping with Twitter to allow the users to log in to your application with their Twitter account:

Map<String, String> twitterFieldsMappings = new HashMap<String, String>();
twitterFieldsMappings.put( "name", "twitter_name" );

Backendless.UserService.loginWithTwitter( this, 
                                          twitterFieldsMappings, 
                                          new AsyncCallback<BackendlessUser>()
{
  @Override
  public void handleResponse( BackendlessUser backendlessUser )
  {
    // user logged in successfully
  }

  @Override
  public void handleFault( BackendlessFault backendlessFault )
  {
    // failed to log in
  }
} );

where:

Argument                Description
twitterFieldsMapping a mapping between the Twitter fields and Backendless user properties. Keys must be the names of the Twitter fields, values - the names of the Backendless properties.
stayLoggedIn a boolean value requesting user login information to be saved on the client side, so it can be reused when the application restarts (or page is reloaded).