Twitter

Your users can login to your application using Twitter after which you can request information about them. Additional setup is required on Twitter - see the setup section at the bottom of the page for more information

Login Flow

Once a user has successfully logged in their access token is automatically saved so you do not need to direct the user to the login screen everytime - check "WSANativeTwitter.IsLoggedIn" first

If a users access token becomes invalid they will have to be directed back to the login page again, you can tell when an access token is invalid as any calls to Twitter apis will fail and the error message will have the Unauthorised property set, "WSANativeTwitter.IsLoggedIn" will also be set to false

Reference the library

C#
using CI.WSANative.Twitter;

Initialise

Initialises the Twitter api - you should call this when your app starts up

The values can all be found on your twitter developer account

C#
WSANativeTwitter.Initialise("consumerKey", "consumerSecret", "oauthCallback");

Login

Shows the Twitter login dialog to the user and if the login is successful returns data about them

If you specify true for include email then you must enable "Request email addresses from users" on the permissions tab on your developer account

If the login is successful WSANativeTwitter.IsLoggedIn will be set to true

C#
WSANativeTwitter.Login(true, r => { if(r.Success) { } });

Logout

Logs the user out i.e removes their access token and sets "WSANativeTwitter.IsLoggedIn" to false

C#
WSANativeTwitter.Logout();

Get user details

Requests details about the logged in user

If you specify true for include email then you must enable "Request email addresses from users" on the permissions tab on your developer account

The response contains the original json message - parse the fields that you need

C#
WSANativeTwitter.GetUserDetails(true, r => { if(r.Success) { string jsonResponse = response.Data; } });

Read any other data about a logged in user

Allows you to call any GET operation on the Twitter api - see the api reference here

The url should be specified as the base url without a query string as in the example below

Query string parameters should be specified as the second argument in the parameters dictionary - can be a null or empty dictionary if there are none

The response contains the original json message - parse the fields that you need

C#
WSANativeTwitter.ApiRead("https://api.twitter.com/1.1/statuses/user_timeline.json", null, r => { if (r.Success) { string jsonResponse = response.Data; } });

Show the tweet dialog

Allows the user to publish a tweet - this does not require any special permissions nor does it require the user to be currently logged in

Additional parameters that can be included are listed here under "Tweet text components" - can be a null or empty dictionary if there are none

The closed action is raised when the dialog is closed

C#
WSANativeTwitter.ShowTweetDialog(parameters, () => { });

Show the retweet dialog

Allows the user to retweet a tweet - this does not require any special permissions nor does it require the user to be currently logged in

The closed action is raised when the dialog is closed

C#
WSANativeTwitter.ShowRetweetDialog("123456", () => { });

Show the like tweet dialog

Allows the user to like a tweet - this does not require any special permissions nor does it require the user to be currently logged in

The closed action is raised when the dialog is closed

C#
WSANativeTwitter.ShowLikeTweetDialog("123456", () => { });

Show the mini profile dialog

Shows a mini view of a profile - this does not require any special permissions nor does it require the user to be currently logged in

You can find a users id from here

The closed action is raised when the dialog is closed

C#
WSANativeTwitter.ShowMiniProfileDialog("123456", () => { });

Show the follow dialog

Allows the user to follow an account - this does not require any special permissions nor does it require the user to be currently logged in

You can find a users id from here

The closed action is raised when the dialog is closed

C#
WSANativeTwitter.ShowFollowDialog("123456", () => { });

Setup

Twitter Developer Site

  1. Register as a developer here
  2. Create a new app (Note the Callback URL field - if you don't know or don't care what goes here enter "https://www.twitter.com/" without quotes
  3. Once you've created the app go the setting tab and ensure that "Allow this application to be used to Sign in with Twitter" is checked
  4. From the keys and access tokens tab note the "Consumer Key" and "Consumer Secret" as you'll need to use them in your app
  5. From the permissions tab set the access level, if you only want to read from Twitter choose "Read Only". Under additional permissions check "Request email addresses from users" if you want access to the users email address

App

  1. Add the internet client capability to your apps manifest file