Twitter

Last Updated On 2021-07-16

Version 4MinSDK 7Tutorial Video

A non-visible component that enables communication with Twitter. Once a user has logged into their Twitter account (and the authorization has been confirmed successful by the IsAuthorized event), many more operations are available:

  • Searching Twitter for tweets or labels (SearchTwitter)
  • Sending a Tweet (Tweet)
  • Sending a Tweet with an Image (TweetWithImage)
  • Directing a message to a specific user (DirectMessage)
  • Receiving the most recent messages directed to the logged-in user (RequestDirectMessages)
  • Following a specific user (Follow)
  • Ceasing to follow a specific user (StopFollowing)
  • Getting a list of users following the logged-in user (RequestFollowers)
  • Getting the most recent messages of users followed by the logged-in user (RequestFriendTimeline)
  • Getting the most recent mentions of the logged-in user (RequestMentions)

You must obtain a Consumer Key and Consumer Secret for Twitter authorization specific to your app from http://twitter.com/oauth_clients/new


Properties

You can set the below properties in the UI part of the builder.

  • ConsumerKey - it's a string value which is set to blank by default.
  • ConsumerSecret - it's a string value which is set to blank by default.

Block Properties

You can set the below blocks properties in the blocks section of the builder.

ConsumerKey

ConsumerKey property getter method.


ConsumerSecret

ConsumerSecret property getter method.


DirectMessages

This property contains a list of the most recent messages mentioning the logged-in user. Initially, the list is empty. To set it, the program must:

  1. Call the Authorize method.
  2. Wait for the Authorized event.
  3. Call the RequestDirectMessages method.
  4. Wait for the DirectMessagesReceived event.
The value of this property will then be set to the list of direct messages retrieved (and maintain that value until any subsequent call to RequestDirectMessages).


Followers

This property contains a list of the followers of the logged-in user. Initially, the list is empty. To set it, the program must:

  1. Call the Authorize method.
  2. Wait for the IsAuthorized event.
  3. Call the RequestFollowers method.
  4. Wait for the FollowersReceived event.
The value of this property will then be set to the list of followers (and maintain its value until any subsequent call to RequestFollowers).


FriendTimeline

This property contains the 20 most recent messages of users being followed. Initially, the list is empty. To set it, the program must:

  1. Call the Authorize method.
  2. Wait for the IsAuthorized event.
  3. Specify users to follow with one or more calls to the Follow method.
  4. Call the RequestFriendTimeline method.
  5. Wait for the FriendTimelineReceived event.
The value of this property will then be set to the list of messages (and maintain its value until any subsequent call to RequestFriendTimeline.


Mentions

This property contains a list of mentions of the logged-in user. Initially, the list is empty. To set it, the program must:

  1. Call the Authorize method.
  2. Wait for the IsAuthorized event.
  3. Call the RequestMentions method.
  4. Wait for the MentionsReceived event.
The value of this property will then be set to the list of mentions (and will maintain its value until any subsequent calls to RequestMentions).


SearchResults

This property, which is initially empty, is set to a list of search results after the program:

  1. Calls the SearchTwitter method.
  2. Waits for the SearchSuccessful event.
The value of the property will then be the same as the parameter to SearchSuccessful. Note that it is not necessary to call the Authorize method before calling SearchTwitter.


TwitPic_API_Key

TwitPicAPIkey property getter method.


Username

The user name of the authorized user. Empty if there is no authorized user.



Methods

You can set the below method blocks in the blocks section of the builder.

Authorize

Redirects user to login to Twitter via the Web browser using the OAuth protocol if we don't already have authorization.

CheckAuthorized

Checks whether we already have access, and if so, causes IsAuthorized event handler to be called.

DeAuthorize

Removes Twitter authorization from this running app instance

DirectMessage

This sends a direct (private) message to the specified user. The message will be trimmed if it exceeds 160characters.

Requirements: This should only be called after the IsAuthorized event has been raised, indicating that the user has successfully logged in to Twitter.

Follow

Starts following a user.

Login

Twitter's API no longer supports login via username and password. Use the Authorize call instead.

RequestDirectMessages

Requests the 20 most recent direct messages sent to the logged-in user. When the messages have been retrieved, the system will raise the DirectMessagesReceived event and set the DirectMessages property to the list of messages.

Requirements: This should only be called after the IsAuthorized event has been raised, indicating that the user has successfully logged in to Twitter.

RequestFollowers

Gets who is following you.

RequestFriendTimeline

Gets the most recent 20 messages in the user's timeline.

RequestMentions

Requests the 20 most recent mentions of the logged-in user. When the mentions have been retrieved, the system will raise the MentionsReceived event and set the Mentions property to the list of mentions.

Requirements: This should only be called after the IsAuthorized event has been raised, indicating that the user has successfully logged in to Twitter.

SearchTwitter

This searches Twitter for the given String query.

Requirements: This should only be called after the IsAuthorized event has been raised, indicating that the user has successfully logged in to Twitter.

StopFollowing

Stops following a user.

Tweet

This sends a tweet as the logged-in user with the specified Text, which will be trimmed if it exceeds 160 characters.

Requirements: This should only be called after the IsAuthorized event has been raised, indicating that the user has successfully logged in to Twitter.

TweetWithImage

This sends a tweet as the logged-in user with the specified Text and a path to the image to be uploaded, which will be trimmed if it exceeds 160 characters. If an image is not found or invalid, only the text will be tweeted.

Requirements: This should only be called after the IsAuthorized event has been raised, indicating that the user has successfully logged in to Twitter.


Events

You can set the below event blocks in the blocks section of the builder.

DirectMessagesReceived

This event is raised when the recent messages requested through RequestDirectMessages have been retrieved. A list of the messages can then be found in the messages parameter or the Messages property.

FollowersReceived

This event is raised when all of the followers of the logged-in user requested through RequestFollowers have been retrieved. A list of the followers can then be found in the followers parameter or the Followers property.

FriendTimelineReceived

This event is raised when the messages requested through RequestFriendTimeline have been retrieved. The timeline parameter and the Timeline property will contain a list of lists, where each sub-list contains a status update of the form (username message)

IsAuthorized

This event is raised after the program calls Authorize if the authorization was successful. It is also called after a call to CheckAuthorized if we already have a valid access token. After this event has been raised, any other method for this component can be called.

MentionsReceived

This event is raised when the mentions of the logged-in user requested through RequestMentions have been retrieved. A list of the mentions can then be found in the mentions parameter or the Mentions property.

SearchSuccessful

This event is raised when the results of the search requested through SearchSuccessful have been retrieved. A list of the results can then be found in the results parameter or the Results property.