Log In with Twitter

First call Twitter.Init (). Then to start Log In with Twitter, call the Twitter.LogIn method, passing success Action, and failure Action.

using TwitterKit.Unity;
...

// Put where your game init code is
Twitter.Init ();
...

public void StartLogin () {
  TwitterSession session = Twitter.Session;
  if (session == null) {
    Twitter.LogIn (LoginComplete, LoginFailure);
  } else {
    LoginComplete (session);
  }
}

public void LoginComplete (TwitterSession session) {
  // Start composer or request email
}

public void LoginFailure (ApiError error) {
  UnityEngine.Debug.Log ("code=" + error.code + " msg=" + error.message);
}

If LogIn completes successfully, a TwitterSession is provided in the success action. This TwitterSession will contain a token, secret, username, and user ID of the user and becomes the active session and is automatically persisted. If you need to retrieve the TwitterSession at a later time, you may do so using the Twitter.Session property.

Request User Email Address

Note

Before using this feature, ensure that “Request email addresses from users” is checked for your Twitter app (https://apps.twitter.com).

To request a user’s email, call the Twitter.RequestEmail method, passing in a valid TwitterSession, success Action, and failure Action.

using TwitterKit.Unity;
...

public void StartRequestEmail () {
  TwitterSession session = Twitter.Session;
  if (session != null) {
    Twitter.RequestEmail (session, RequestEmailComplete, RequestEmailFailure);
  } else {
    startLogin();
  }
}

public void RequestEmailComplete (String email) {
  // Save email
}

public void RequestEmailFailure (ApiError error) {
  UnityEngine.Debug.Log ("code=" + error.code + " msg=" + error.message);
}