Retrieving OAuth Tokens

Note: Retrieving OAuth Tokens is being currently supported only for the Android Platform.

After twitter Authentication is successful, you can request OAuth Tokens as showed on the snapshot below:

string AccessToken 		 = AndroidTwitterManager.instance.AccessToken;
string AccessTokenSecret = AndroidTwitterManager.instance.AccessTokenSecret;

 

With this tokens you will be able to send the request directly from the C#.  With this tokens you can use any methods from the Twitter Rest API.

The Unity WWW class can be used for this. The approach how to create and format request is described here.

 

As an alternative to creating your own client for query Twitter Rest API, you can use TW_OAuthAPIRequest class. The following code snippet shows how to query home_timeline with optional count param set to 1.

TW_OAuthAPIRequest request =  TW_OAuthAPIRequest.Create();

request.AddParam("count", 1);
request.Send("https://api.twitter.com/1.1/statuses/home_timeline.json");
request.OnResult += OnResult;
	

void OnResult (TW_APIRequstResult result) {
	Debug.Log("Is Request Succeeded: " + result.IsSucceeded);
	Debug.Log("Responce data:");
	Debug.Log(result.responce);
}

Warning: Such request can be performed only after the user is Auntheficated. Otherwise TW_OAuthAPIRequest will not be able to get access token and secret.

After response is received,  you can parse JSON data provided by twitter. 

With TW_OAuthAPIRequest  you can test your API implementation directly in the editor. But as we cannot perform auth in the unity editor (only in real device), you need to specify a static access token and secret. You can get token and secret for your personal twitter account directly in the twitter documentation, and specify it in the plugin settings. Step by step guide can be found below:

1) Open request documentation you would like to implement,  home_timeline for example.

2) Scroll down to the OAuth Signature Generator section, and pick your app from the dropdown. It will redirect you to the page where you can copy access token and secret for your account.

3) Open the plugin editor settings under Windows â Mobile Social Plugin â Edit Settings. And copy access token and secret to the plugin editor settings as showed on the screenshot below

Note: Access Token and Secret specified under editor settings will be used only on the editor platform and only for the testing purposes.