Integrating Twitter Account

This page covers how to allow your user to sign up for and log in to your mobile app with their Twitter accounts. Just making some small configuration on the developer portal and executing a few REST APIs are all you need to make your application ready!

Configuring Twitter Integration

Create a Twitter App

To get started, you first need to create a Twitter App. Please refer the official guide for the detailed instructions.

You will need to fill in the following fields (please put your AppID in ${your-app-id}):

  • Name
  • Description
  • Website
  • Callback URL
    • United States: https://${your-app-id}.us.kiiapps.com/api/apps/${your-app-id}/integration/webauth/callback
    • Japan: https://${your-app-id}.jp.kiiapps.com/api/apps/${your-app-id}/integration/webauth/callback
    • Singapore: https://${your-app-id}.sg.kiiapps.com/api/apps/${your-app-id}/integration/webauth/callback
    • Europe: https://${your-app-id}.eu.kiiapps.com/api/apps/${your-app-id}/integration/webauth/callback

When your Twitter app is created, you will get a "Consumer Key" and "Consumer Secret".

Configuring a Kii application

Take the following steps in the developer portal to configure your application by setting your Consumer Key and Consumer Secret.

  1. Click on the "Edit" button in your application console at the developer portal.

  2. Click on "Settings" to bring up the application's configuration menu.

  3. Paste your Twitter Consumer Key and Secret.

Get the Twitter Access Token

Your application must get the Twitter access token by itself. See this document for more details.

Login with Twitter Account

Here is an example for letting a new user logs in with theirTwitter account. Put the Twitter access token and token secret in {ACCESS_TOKEN_PROVIDED_BY_TWITTER} and {ACCESS_SECRET_PROVIDED_BY_TWITTER}, respectively.

curl -v -X POST \
  -H "Authorization: Basic {BASE64_ENCODED_APPID_AND_APPKEY}" \
  -H "Content-Type: application/vnd.kii.AuthTokenTwitterRequest+json" \
  "https://api.kii.com/api/apps/{APP_ID}/integration/twitter" \
  -d '{
    "accessToken": "{ACCESS_TOKEN_PROVIDED_BY_TWITTER}",
    "accessTokenSecret": "{ACCESS_SECRET_PROVIDED_BY_TWITTER}"
  }'

You log in with Basic Authentication. Replace {BASE64_ENCODED_APPID_AND_APPKEY} with a Base64-encoded string of concatenated AppID and an arbitrary value with a colon (:) in between the two values.

Once the user's identity has been verified with Twitter, Kii Cloud will check if the user is new or existing within your application. If it is a new user, Kii Cloud will automatically create a new account.

Upon the successful sign-up/login, Kii Cloud will return an access token for the user along with this user's User ID and the expiration duration of the token (sec):

< 200
< Content-Type: application/json
<
{
  "id" : {USER_ID},
  "access_token" : {ACCESS_TOKEN},
  "expires_in" : 9223372036854775,
  "new_user_created": true
}

The new_user_created key will be set as true if Kii Cloud performed a registration for the new user.

Linking a Kii Account to a Twitter Account

By linking existing applications with their social accounts, they will have an alternative to authentication - in addition to their existing passwords.

curl -v -X POST \
  -H "Authorization: Bearer {ACCESS_TOKEN}" \
  -H "Content-Type: application/vnd.kii.LinkTwitterRequest+json" \
  "https://api.kii.com/api/apps/{APP_ID}/users/me/twitter/link" \
  -d '{
    "accessToken": "{ACCESS_TOKEN_PROVIDED_BY_TWITTER}",
    "accessTokenSecret": "{ACCESS_SECRET_PROVIDED_BY_TWITTER}"
  }'

If successful, Kii Cloud will respond as shown below:

< 204 (No content)

Unlinking a Kii Account from a Twitter Account

You can unlink the existing users from their Twitter accounts in the following manner:

curl -v -X POST \
  -H "Authorization: Bearer {ACCESS_TOKEN}" \
  "https://api.kii.com/api/apps/{APP_ID}/users/me/twitter/unlink" \
  -d ""

If successful, Kii Cloud will respond as shown below:

< 204 (No content)