"Twitter" (Service Connection)

Connect your Twitter account to the Wolfram Language to analyze Twitter data like tweets, retweets, replies, and followers. Also send tweets directly from the Wolfram Language.

Connecting & Authenticating

    ServiceConnect["Twitter"] creates a connection to the Twitter API. If a previously saved connection can be found, it will be used; otherwise, a new authentication request will be launched.

Requests

    ServiceExecute[conn,"request",params] sends a request to the connection identified by conn, using parameters params. The following give possible requests.

    User Information

    Requests:

    "UserData" profile information for any user

    Parameters:
  • "Username"authenticated userthe Twitter name
    "UserID"authenticated userthe user ID number
  • Requests:

    "UserMentions" list of user handles included in a timeline

    "UserReplies" user's replies

    "UserHashtags" hashtags in user's tweets

    Parameters:
  • "Username"authenticated userthe Twitter name
    "UserID"authenticated userthe user ID number
    MaxItems20number of results to return
  • Friends and Followers Information

    Requests:

    "Friends" who a user is following, or a list of names of the users followed by the provided user

    "FriendIDs" list of IDs of the users followed by the provided user

    "Followers" who is following a user, or a list of names of the users following the provided user

    "FollowerIDs" list of IDs of the users following the provided user

    Parameters:
  • "Username"authenticated userthe Twitter name
    "UserID"authenticated userthe user ID number
    MaxItems5000number of results to return
  • Requests:

    "FriendNetwork" graph of which of the user's friends follow each other

    "FollowerNetwork" graph of which of the user's followers follow each other

    "FriendMentionNetwork" graph of which friends mention each other

    "FollowerMentionNetwork" graph of which followers mention each other

    "FriendReplyToNetwork" graph of which friends reply to each other

    "FollowerReplyToNetwork" graph of which followers reply to each other

    Parameters:
  • "Username"authenticated userthe Twitter name
    "UserID"authenticated userthe user ID number
  • Sending Tweets

    Requests:

    "Tweet" send a tweet

    Parameters:
  • "Message"(required)message to send
    "InReplyToStatusID"Nonetweet ID being replied to
    GeoLocationNonelocation of the tweet
    "Image"Noneimage or list of images to attach to the tweet (max. 4)
  • Requests:

    "Retweet" Retweet a tweet

    Parameters:
  • "TweetID"(required)tweet ID to be retweeted
  • Retrieving Tweets

    Requests:

    "GetTweet" get a tweet

    Parameters:
  • "TweetID"(required)tweet ID to be retrieved
    "Elements""Data"
  • data elements to return
  • Requests:

    "TweetList" get a list of tweets

    Parameters:
  • "Username"authenticated userthe Twitter name
    "UserID"authenticated userthe user ID number
    MaxItems20number of results to return
    "Elements""Data"
  • data elements to return
  • "SinceID"Noneearliest tweet ID to use
    "MaxID"Nonelatest tweet ID to use
  • Requests:

    "TweetTimeline" get a timeline of tweets

    "TweetEventSeries" get tweets as a series of events

    Parameters:
  • "Username"authenticated userthe Twitter name
    "UserID"authenticated userthe user ID number
    MaxItems20number of results to return
  • Requests:

    "LastTweet" user's latest tweet

    Parameters:
  • "Username"authenticated userthe Twitter name
    "UserID"authenticated userthe user ID number
  • Content Search & Followers

    Requests:

    "TweetSearch" find recent tweets associated with a specified content search string

    Parameters:
  • "Query"(required)search string
    MaxItems20number of results to return
    "Language"Nonelanguage entity of the tweet
    "ResultType"Nonetype of tweet
    GeoLocationNonelocation of the tweet
    "Radius"radius around the location. This parameter will be used only if the GeoLocation parameter is included
  • Requests:

    "UserIDSearch" find user IDs associated with a specified content search string

    "SearchNetwork" follower network based on a specified content search string

    "SearchMentionNetwork" mention network based on a specified content search string

    "SearchReplyToNetwork" reply network based on a specified content search string

    Parameters:
  • "Query"(required)search string
    MaxItems20number of users to return
  • Access Information

    Requests:

    "RateLimit" check number of available and used requests for this connection

Parameter Details

    Possible settings for "Elements" include:
  • "Data"return a dataset with a limited set of fields
    "Images"return a list of images
    "FullData"return a dataset with all available fields
    "Text"return a list of texts
  • Possible settings for "ShowThumbnails" include:
  • Trueincludes thumbnails
    Falseincludes thumbnails' URLs
  • Possible settings for "ResultType" include:
  • "Recent"return the latest tweets
    "Popular"return popular tweets

Examples

Basic Examples  (8)

Create a new connection:

In[1]:=
Click for copyable input
Out[1]=

Get information about any user. "UserID" and "Username" are both valid inputs:

In[2]:=
Click for copyable input
Out[2]=
In[3]:=
Click for copyable input
Out[3]=

Get replies from a user:

In[1]:=
Click for copyable input
Out[1]=

Get hashtags in a user's tweets:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

See who a user is following:

In[1]:=
Click for copyable input
Out[1]=

See who is following a user:

In[2]:=
Click for copyable input
Out[2]=

Plot your friend network:

In[1]:=
Click for copyable input
Out[1]=

Tweet a message:

In[1]:=
Click for copyable input
Out[1]=

Tweet an image:

In[2]:=
Click for copyable input
In[3]:=
Click for copyable input
Out[3]=

Tweet multiple images:

In[4]:=
Click for copyable input
In[5]:=
Click for copyable input
Out[5]=

Get basic information about a tweet:

In[1]:=
Click for copyable input
Out[1]=

Get the images of a tweet:

In[2]:=
Click for copyable input
Out[2]=

Search recent tweets with a specific hashtag:

In[1]:=
Click for copyable input
Out[1]=

Search recent tweets using a phrase:

In[2]:=
Click for copyable input
Out[2]=