Cross Platform Native Plugins
A true cross platform tool for Unity which provides unique and unified way to access native functionality on mobile platforms.
Public Member Functions | List of all members
Twitter Class Reference

Provides cross-platform interface to Twitter login and sending requests on the behalf of the user. Additionally, it includes methods to compose and send Tweet messages. More...

Public Member Functions

virtual bool Initialise ()
 Initialises the SDK with the credentials set in NPSettings. More...
 
virtual void Login (TWTRLoginCompletion _onCompletion)
 Authenticates the app user with Twitter. More...
 
virtual void Logout ()
 Deletes the Twitter user session from this app. More...
 
virtual bool IsLoggedIn ()
 Determines whether user is currently logged in to Twitter. More...
 
virtual string GetAuthToken ()
 Returns the authorization token of the current user session. More...
 
virtual string GetAuthTokenSecret ()
 Returns the authorization token secret of the current user session. More...
 
virtual string GetUserID ()
 Returns the user ID associated with the access token. More...
 
virtual string GetUserName ()
 Returns the username associated with the access token. More...
 
void ShowTweetComposerWithMessage (string _message, TWTRTweetCompletion _onCompletion)
 Shows a view to compose and send Tweet message. More...
 
void ShowTweetComposerWithScreenshot (string _message, TWTRTweetCompletion _onCompletion)
 Shows a view to compose and send Tweet message. More...
 
void ShowTweetComposerWithImage (string _message, Texture2D _texture, TWTRTweetCompletion _onCompletion)
 Shows a view to compose and send Tweet message. More...
 
void ShowTweetComposerWithLink (string _message, string _URL, TWTRTweetCompletion _onCompletion)
 Shows a view to compose and send Tweet message. More...
 
virtual void ShowTweetComposer (string _message, string _URL, byte[] _imgByteArray, TWTRTweetCompletion _onCompletion)
 Shows a view to compose and send Tweet message. More...
 
virtual void RequestAccountDetails (TWTRAccountDetailsCompletion _onCompletion)
 Requests access to the current Twitter user account details. More...
 
virtual void RequestEmailAccess (TWTREmailAccessCompletion _onCompletion)
 Requests access to the email address associated with current Twitter user. More...
 
void GetURLRequest (string _URL, IDictionary _parameters, TWTRResonse _onCompletion)
 Sends a signed Twitter Get request. More...
 
void PostURLRequest (string _URL, IDictionary _parameters, TWTRResonse _onCompletion)
 Sends a signed Twitter Post request. More...
 
void PutURLRequest (string _URL, IDictionary _parameters, TWTRResonse _onCompletion)
 Sends a signed Twitter Put request. More...
 
void DeleteURLRequest (string _URL, IDictionary _parameters, TWTRResonse _onCompletion)
 Sends a signed Twitter Delete request. More...
 
delegate void TWTRLoginCompletion (TwitterSession _session, string _error)
 Delegate that will be called when authentication process is complete. More...
 
delegate void TWTRTweetCompletion (eTwitterComposerResult _result)
 Delegate that will be called when Tweet composer is dismissed. More...
 
delegate void TWTRAccountDetailsCompletion (TwitterUser _user, string _error)
 Delegate that will be called when user account details are retrieved. More...
 
delegate void TWTREmailAccessCompletion (string _email, string _error)
 Delegate that will be called when email access request completes. More...
 
delegate void TWTRResonse (object _responseData, string _error)
 Delegate that will be called when Twitter request completes. More...
 

Detailed Description

Provides cross-platform interface to Twitter login and sending requests on the behalf of the user. Additionally, it includes methods to compose and send Tweet messages.

You will need a consumer key and a consumer secret to use Twitter SDK within your application. And for this, please follow the instructions provided by Twitter and set it in NPSettings.

Member Function Documentation

virtual bool Initialise ( )
virtual

Initialises the SDK with the credentials set in NPSettings.

Returns
true if SDK got initialised; otherwise, false.
Note
You need to call this method, before using any features. This method requires that you have set up your consumerKey and consumerSecret in NPSettings.
virtual void Login ( TWTRLoginCompletion  _onCompletion)
virtual

Authenticates the app user with Twitter.

This method falls back to presenting an OAuth flow, if it fails to find saved login credentials.

Parameters
_onCompletionCallback that will be called after operation is completed.
Note
User authentication is required for API requests that require a user context, for example: Tweeting or following other users.

The following code shows how to use login method.

using System.Collections;
public class ExampleClass : MonoBehaviour
{
public void Login ()
{
NPBinding.Twitter.Login(LoginFinished);
}
private void OnLoginFinished (TwitterSession _session, string _error)
{
if (_error == null)
{
// Logged in successfully
}
else
{
// Login failed
}
}
}
virtual void Logout ( )
virtual

Deletes the Twitter user session from this app.

virtual bool IsLoggedIn ( )
virtual

Determines whether user is currently logged in to Twitter.

Returns
true if user is currently logged into Twitter; otherwise, false.
virtual string GetAuthToken ( )
virtual

Returns the authorization token of the current user session.

Returns
The authorization token.
Note
Returns null if there is no logged in user.
virtual string GetAuthTokenSecret ( )
virtual

Returns the authorization token secret of the current user session.

Returns
The authorization token secret.
Note
Returns null if there is no logged in user.
virtual string GetUserID ( )
virtual

Returns the user ID associated with the access token.

Returns
The user ID associated with the access token.
Note
Returns null if there is no logged in user.
virtual string GetUserName ( )
virtual

Returns the username associated with the access token.

Returns
The username associated with the access token.
Note
Returns null if there is no logged in user.
void ShowTweetComposerWithMessage ( string  _message,
TWTRTweetCompletion  _onCompletion 
)

Shows a view to compose and send Tweet message.

Parameters
_messageThe initial text for the Tweet.
_onCompletionCallback that will be called after operation is completed.
void ShowTweetComposerWithScreenshot ( string  _message,
TWTRTweetCompletion  _onCompletion 
)

Shows a view to compose and send Tweet message.

Parameters
_messageThe initial text for the Tweet.
_onCompletionCallback that will be called after operation is completed.
void ShowTweetComposerWithImage ( string  _message,
Texture2D  _texture,
TWTRTweetCompletion  _onCompletion 
)

Shows a view to compose and send Tweet message.

Parameters
_messageThe initial text for the Tweet.
_textureUnity texture object that has to be shared in the Tweet.
_onCompletionCallback that will be called after operation is completed.
void ShowTweetComposerWithLink ( string  _message,
string  _URL,
TWTRTweetCompletion  _onCompletion 
)

Shows a view to compose and send Tweet message.

Parameters
_messageThe initial text for the Tweet.
_URLURL that has to be shared in the Tweet.
_onCompletionCallback that will be called after operation is completed.
virtual void ShowTweetComposer ( string  _message,
string  _URL,
byte[]  _imgByteArray,
TWTRTweetCompletion  _onCompletion 
)
virtual

Shows a view to compose and send Tweet message.

Parameters
_messageThe initial text for the Tweet.
_URLURL that has to be shared in the Tweet.
_imgByteArrayRaw image data that has to be shared in the Tweet.
_onCompletionCallback that will be called after operation is completed.
virtual void RequestAccountDetails ( TWTRAccountDetailsCompletion  _onCompletion)
virtual

Requests access to the current Twitter user account details.

Parameters
_onCompletionCallback that will be called after operation is completed.

The following code snippet shows how to fetch account details of current user.

using System.Collections;
public class ExampleClass : MonoBehaviour
{
public void FetchAccountDetails ()
{
NPBinding.Twitter.RequestAccountDetails(OnRequestFinished);
}
private void OnRequestFinished (TwitterUser _user, string _error)
{
if (_error == null)
{
Debug.Log("Logged in user name is: " + _user.Name);
}
else
{
// Something went wrong
}
}
}
virtual void RequestEmailAccess ( TWTREmailAccessCompletion  _onCompletion)
virtual

Requests access to the email address associated with current Twitter user.

Parameters
_onCompletionCallback that will be called after operation is completed.

The following code snippet shows how to fetch email address of current user.

using System.Collections;
public class ExampleClass : MonoBehaviour
{
public void FetchEmailAddress ()
{
NPBinding.Twitter.RequestEmailAccess(OnRequestFinished);
}
private void OnRequestFinished (string _email, string _error)
{
if (_error == null)
{
Debug.Log("Email id: " + _email);
}
else
{
// Something went wrong
}
}
}
void GetURLRequest ( string  _URL,
IDictionary  _parameters,
TWTRResonse  _onCompletion 
)

Sends a signed Twitter Get request.

Parameters
_URLRequest URL. This is the full Twitter API URL. E.g. https://api.twitter.com/1.1/statuses/user_timeline.json.
_parametersRequest parameters.
_onCompletionCallback that will be called after operation is completed.

The following code shows how to send request to Twitter.

using System.Collections;
using System.Collections.Generic;
public class ExampleClass : MonoBehaviour
{
public void SendRequest ()
{
string _URL = "https://api.twitter.com/1.1/statuses/show.json";
IDictionary _params = new Dictionary<string, string>(){
{"id", "20"}
};
NPBinding.Twitter.GetURLRequest(_URL, _params, OnRequestFinished);
}
private void OnRequestFinished (object _responseData, string _error)
{
if (_error == null)
{
IDictionary _JSONDict = (IDictionary)_responseData;
// Extract values from JSON object
}
else
{
// Something went wrong
}
}
}
void PostURLRequest ( string  _URL,
IDictionary  _parameters,
TWTRResonse  _onCompletion 
)

Sends a signed Twitter Post request.

Parameters
_URLRequest URL. This is the full Twitter API URL. E.g. https://api.twitter.com/1.1/statuses/user_timeline.json.
_parametersRequest parameters.
_onCompletionCallback that will be called after operation is completed.
void PutURLRequest ( string  _URL,
IDictionary  _parameters,
TWTRResonse  _onCompletion 
)

Sends a signed Twitter Put request.

Parameters
_URLRequest URL. This is the full Twitter API URL. E.g. https://api.twitter.com/1.1/statuses/user_timeline.json.
_parametersRequest parameters.
_onCompletionCallback that will be called after operation is completed.
void DeleteURLRequest ( string  _URL,
IDictionary  _parameters,
TWTRResonse  _onCompletion 
)

Sends a signed Twitter Delete request.

Parameters
_URLRequest URL. This is the full Twitter API URL. E.g. https://api.twitter.com/1.1/statuses/user_timeline.json.
_parametersRequest parameters.
_onCompletionCallback that will be called after operation is completed.
delegate void TWTRLoginCompletion ( TwitterSession  _session,
string  _error 
)

Delegate that will be called when authentication process is complete.

Parameters
_sessionContains the OAuth tokens and minimal information associated with the logged in user or nil.
_errorIf the operation was successful, this value is nil; otherwise, this parameter holds the description of the problem that occurred.
delegate void TWTRTweetCompletion ( eTwitterComposerResult  _result)

Delegate that will be called when Tweet composer is dismissed.

delegate void TWTRAccountDetailsCompletion ( TwitterUser  _user,
string  _error 
)

Delegate that will be called when user account details are retrieved.

Parameters
_userThe logged in Twitter user.
_errorIf the operation was successful, this value is nil; otherwise, this parameter holds the description of the problem that occurred.
delegate void TWTREmailAccessCompletion ( string  _email,
string  _error 
)

Delegate that will be called when email access request completes.

Parameters
_emailThe logged in Twitter user's email address. This value is null if the user does not grant access to their email address or your application is not allowed to request email addresses.
_errorIf the operation was successful, this value is null; otherwise, this parameter holds the description of the problem that occurred.
delegate void TWTRResonse ( object  _responseData,
string  _error 
)

Delegate that will be called when Twitter request completes.

Parameters
_responseDataResponse to a Twitter request.
_errorIf the operation was successful, this value is nil; otherwise, this parameter holds the description of the problem that occurred.