Release Notes: (1.4.0)
  • iOS arm64 architecture support added..

Integration Guide - Twitter SNS Plugin

Platforms: Android & iOS
Plugin version: 1.4.0
Twitter iOS API version: 1.1
Twitter Android API version: 1.1

Generally you don't have to dive into the documentation from Twitter, simply follow a few steps below to get the plugin integrated in your App in minutes:

PREPARATION:

· >>> You will need to create your App at Twitter Dev Site, before you integrate the plugin. And please make sure the "Callback URL" (under "OAuth Settings" section) is filled in, it can be an arbitrary URL, just for enabling the callback in your App; "Sign In With Twitter" is required to be checked to have the authentication work in your App. Also please make sure your have at least "Read & Write" Access permission set up for your App, this can be done in Twitter Dev Site, select your App, go to "Permissions" tab, then select "Read & Write" access level.

[1] Import the TwitterSNS[Android|IOS|Universal].unitypackage file to your unity project;

[2] Follow the instructions below to configure the plugin.

· >>> For Android platform, click on the menu item of Unity top menu bar: NeatPlug -> TwitterSNS -> Patch Android Configuration. This is for generating a valid AndroidManifest.xml or patching the existing file with TwitterSNS support.


· >>> For iOS platform, click on the menu item of Unity top menu bar: NeatPlug -> TwitterSNS -> Patch iOS Configuration. This is for automatically adding iOS SDK frameworks, libraries or patching the Info.plist file (if needed) as long as the Xcode project is generated by Unity.

[3] Find TwitterSNSAgent Prefab and TwitterSNSListener Prefab in Assets/Plugins/NeatPlug/SNS/TwitterSNS/Prefabs/, open the first scene of your game, drag & drop those two prefabs into the scene.

[4] Okay, the integration is done here. Now set up your Twitter SNS by filling in a few properties of the TwitterSNSAgent gameObject which you just dropped in the Hierarchy window. To do this, simply select that gameObject, and look at its properties in the Inspector window, you need to fill in:

   · Consumer Key [Android|IOS] - Your Consumer Key for Android or IOS, this can be obtained from Twitter Developer Site.

   · Consumer Secret [Android|IOS] - Your Consumer Secret for Android or IOS, this can be obtained from Twitter Developer Site.

[5] After you supply above info that the plugin needs, posting on twitter can be as easy as a single line of codes. You can call below methods to post the messages (status updates) or screenshots of your game to twitter.

NOTE: The plugin will automatically retrieve user's information for you once the user logged into twitter, you can make use of that info if you need, the user's information will be sent to you via TwitterSNSListener::OnUserInfoArrived(), for more details, goto [6].

 

  Call the following methods to initialize and post on twitter:

   · TwitterSNS.Instance().Init(...) - Required if you don't apply "Consumer Key" and "Consumer Secret" values for TwitterSNSAgent.

   · TwitterSNS.Instance().PostMessage(...) - Post a message (status update), will show login box if the user not yet logged into twitter.

   · TwitterSNS.Instance().PostScreenShot(...) - Post a screenshot of your App, will show login box if the user not yet logged into twitter.

   · TwitterSNS.Instance().PostImage(...) - Post an image, will show login box if the user not yet logged into twitter.

   · TwitterSNS.Instance().GetUserHomeTimeline() - Fetch all past tweets from the user's home timeline on twitter.

   · TwitterSNS.Instance().FollowUser(...) - Follow a twitter user, will show login box if the user not yet logged into twitter.

  There are other useful public methods that TwitterSNS provides, to use them, simply call TwitterSNS.Instance().methodName().
Show All   
public void Init(string consumerKey, string consumerSecret)
/**
 * Initialize the environment.
 * 
 * @param consumerKey
 *            string - The ConsumerKey got from twitter dev site.
 * 
 * @param consumerSecret
 *            string - The ConsumerSecret got from twitter dev site.
 * 	
 */
public void Init(string consumerKey, string consumerSecret)
public void PostScreenShot(string description = null)
/**
 * Capture and post the screenshot of your App on the user's wall.
 * 
 * NOTE: Screenshot capturing is having issue on Android with Unity3.4.x, 
 * you may want to upgrade to Unity4 to get it work. That is a Unity bug.
 * 
 * @param description
 *               string - Description for the screenshot.
 *
 */
public void PostScreenShot(string description = null)
public void PostImage(byte[] imgBytes, string description = null)
/**
 * Post an image for the user.
 * 
 * @param imgBytes
 *          byte[] - The image data.
 * 
 * @param description
 *          string - Description for the image.
 */	
public void PostImage(byte[] imgBytes, string description = null)
public void PostMessage(string message, string link  = null)
/**
 * Post a message (status update) for the user.
 *
 * NOTE: The text to be posted must not exceed Twitter's maximum characters
 * limit, please be aware of that the link will also take up some room although
 * it would be shortened.
 * (As of this document is written, the limit is 140.)
 *
 * @param message
 *           string - The message to be posted.
 * 
 * @param link
 *           string - The link to be posted.
 */
public void PostMessage(string message, string link  = null)
public void Login()
/**
 * Show up a twitter login box.
 * 
 * You may need to call this function if you want the user to login whenever you want, 
 * instead of logging in at the time when posting a message (status update) or screenshot.
 * 
 * A usecase is that you let the user login every time your game starts.
 * 
 */
public void Login()
public void Logout()
/**
 * Log out the user.
 */
public void Logout()
public void GetUserHomeTimeline()
/**
 * Fetch all past tweets from the user's home timeline on twitter.
 * 
 * Your app will be notified with the fetched tweets by 
 * TwitterSNSListener::OnUserTimelineDataArrived() event.
 * 
 */
public void GetUserHomeTimeline()
public void FollowUser(string userScreenName)
/**
 * Follow a twitter user.
 * 
 * @param userScreenName
 *             string - The screen name of the user.
 */
public void FollowUser(string userScreenName)

[6] For advanced users who need to handle Twitter events, Read this:

  Follow the instructions to handle Twitter events:

  · Select the dropped TwitterSNSListener gameObject, locate the TwitterSNSListener.cs script, open it and make some modifications.

  These callbacks are exposed in the script, you can supply your own implementations in them.
Show All   
void OnUserLoggedIn() { ... }
/**
 * Fired when the user successfully logged in.
 */
void OnUserLoggedIn()
{
    /// Your code here...   
}
void OnUserFailedToLogIn() { ... }
/**
 * Fired when the user failed to login.
 * 
 * @param err
 *          string - The error string
 */
void OnUserFailedToLogIn()
{
    /// Your code here...   
}
void OnUserLoggedOut() { ... }
/**
 * Fired when the user is logged out.
 */
void OnUserLoggedOut()
{
    /// Your code here...   
}
void OnScreenShotPosted() { ... }
/**
 * Fired when a screenshot is successfully posted.
 */
void OnScreenShotPosted()
{
    /// Your code here...   
}
void OnFailedToPostScreenShot(string err) { ... }
/**
 * Fired when failed to capture and post a screenshot.
 * 
 * @param err
 *         string - The error string.
 */
void OnFailedToPostScreenShot(string err)
{
    /// Your code here...
}
void OnImagePosted() { ... }
/**
 * Fired when an image is successfully posted.
 */
void OnImagePosted()
{
    /// Your code here...   
}
void OnFailedToPostImage(string err) { ... }
/**
 * Fired when failed to post an image.
 * 
 * @param err
 *         string - The error string.
 */
void OnFailedToPostImage(string err)
{
    /// Your code here...
}
void OnMessagePosted() { ... }
/**
 * Fired when a message is successfully posted.
 */
void OnMessagePosted()
{
    /// Your code here...
}
void OnFailedToPostMessage(string err) { ... }
/**
 * Fired when failed to post a message.
 * 
 * @param err
 *          string - The error string
 */
void OnFailedToPostMessage(string err)
{
    /// Your code here...
}
void OnUserTimelineDataArrived(List<TwitterTimelineStatus> statuses) { ... }
/**
 * Fired when user's home timeline information arrived.	 	
 * 
 * @param statuses
 *          List - A list of tweets.
 */
void OnUserTimelineDataArrived(List<TwitterTimelineStatus> statuses)
{
    /// Your code here...
}
void OnFailedToGetUserTimelineData(string err) { ... }
/**
 * Fired when failed to get user's home timeline.
 *
 * @param err
 *          string - The error string
 */
void OnFailedToGetUserTimelineData(string err)
{
    /// Your code here...
}
void OnUserInfoArrived(TwitterUserInfo userInfo) { ... }
/**
 * Fired when the user info data arrived. 
 * 
 * @param userInfo
 *         TwitterUserInfo - An object containing the user info. 
 */
void OnUserInfoArrived(TwitterUserInfo userInfo)
{
    /// Your code here...
}
void OnFailedToGetUserInfo(string err) { ... }
/**
 * Fired when failed to get user info.
 *
 * @param err
 *          string - The error string
 */
void OnFailedToGetUserInfo(string err)
{
    /// Your code here...
}
void OnUserFollowed(string userScreenName) { ... }
/**
 * Fired when successfully followed a user.
 * 
 * @param userScreenName
 *         string - The user's screen name.
 */
void OnUserFollowed(string userScreenName)
{
    /// Your code here...   
}
void OnFailedToFollowUser(string userScreenName, string err) { ... }
/**
 * Fired when failed to follow a user.
 * 
 * @param userScreenName
 *         string - The user's screen name.
 * 
 * @param err
 *         string - The error string.
 */
void OnFailedToFollowUser(string userScreenName, string err)
{
    /// Your code here...
}

[7] Build your App now.

[8] Test and verify if the Twitter functions work as expected, it would be helpful for you to address issues if you take a look at the logcat output (Android) or xcode debug console (iOS) to find the debug / error / warning messages.

[EOF] Should you have any questions or encounter any problems while integrating the plugin, please do not hesitate to shoot us an email at support@neatplug.com, we will be more than happy to help you. Thanks for choosing NeatPlug solutions!