Skip to content

Authenticated User

linvi edited this page Nov 2, 2017 · 6 revisions

Overview

An AuthenticatedUser is a User who is associated with a set of credentials. This User therefore has additional methods that will use his own credentials.

Let's code!

Create an Authenticated User

An AuthenticatedUser can be created using the current thread set of credentials, or you can use a set of credentials and create it from the User.GetAuthenticatedUser method.

// Get the AuthenticatedUser from the current thread credentials
var authenticatedUser = User.GetAuthenticatedUser();

// OR

// Get a AuthenticatedUser from a specific set of credentials
var userCredentials = Auth.CreateCredentials("CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET");
var authenticatedUser = User.GetAuthenticatedUser(userCredentials);

Work with the Authenticated User

An AuthenticatedUser contains a new set of methods in addition to the one available from the User class. When invoking any of these new methods from the AuthenticatedUser, the operation will use the credentials associated with this user (authenticatedUser.Credentials).

For example you can get his Home Timeline, his account settings, private messages...

// Timeline
var homeTimeline = authenticatedUser.GetHomeTimeline();

// Settings
var accountSettings = authenticatedUser.GetAccountSettings();

// Messages
var latestMessagesReceived = authenticatedUser.GetLatestMessagesReceived();
var latestMessagesSent = authenticatedUser.GetLatestMessagesSent();

// Relationships
var relationshipDetails = authenticatedUser.GetRelationshipWith("tweetinviapi");
var success = authenticatedUser.FollowUser("tweetinviapi");

var incomingFriendshipRequests = authenticatedUser.GetUsersRequestingFriendship();
var outgoingFriendshipRequests = authenticatedUser.GetUsersYouRequestedToFollow();

// Saved Searches
var savedSearches = authenticatedUser.GetSavedSearches();

// Lists
var success = authenticatedUser.SubsribeToList(<list_identifier>);

// Block and Report
var success = authenticatedUser.ReportUserForSpam("mean_person");
var success = authenticatedUser.BlockUser("person_speaking_too_much!");

// ... Intellisense is your friend now!
Clone this wiki locally