Message Boards Message Boards

Avoid issues while retrieving tweets via Twitter connection?

Friends, I have a problem with the Twitter connection. I establish a connection and suppose I give it the name "conex".

So for example I can retrieve the tweets of somebody named María T woth the following command:

conex["TweetList", "Username" -> "María T", MaxItems -> 10]

Now I have three distinct questions:: a. I want to get only the text of the tweets by María T. Something like "Elements"->"Texts", But I have not managed to do it. How can i do it? b. I want to get only the tweets by María te that contain a specific string. So here I want to combine the utilities of "TweetSearch" with those of "TweetList". Once again, I have not been able to do it. Is there a solution? c. Sometimes, the tweet appears truncated. Is Mathematica still operating under the assumption of 140 character tweets, or did it already adapt to the 280 characters standard.

Any help appreciated

Francisco

3 Replies

Hugely useful, many thanks!

a-> You can get the Text for tweets by post processing the data returned from twitter api.

In[3]:= twitter = ServiceConnect["Twitter", "New"]

Out[3]= ServiceObject["Twitter", 
 "ID" -> "connection-daaea6b1e90f6335cc7d7da583b4899c"]

In[38]:= res = 
 twitter["TweetList", MaxItems -> 2, "Username" -> "elonmusk"]

Out[38]= Dataset[ <> ]

In[39]:= (res[#]["Text"]) & /@ Range[res // Length]

Out[39]= {"RT @SpaceX: Successful deployment of SES-12 to a \
geostationary transfer orbit confirmed.", "RT @SpaceX: Falcon 9 and \
SES-12 went vertical this morning on Pad 40 in Florida. Weather is \
70% favorable for the four-hour launch window w\[Ellipsis]"}

b-> TweetSearch do not support querying text based tweets for a specific user.

c-> Tweets > 140 characters are supported.

In[42]:= ans1 = 
 ServiceExecute[twitter, "GetTweet", 
   "TweetID" -> 951803393345015808][["Text"]]
StringLength[ans1]

Out[42]= "@Raspberry_Pi @MakeUseOf I put up my first Raspberry Pi \
twitter bot earlier this week. It plays the game \
\[OpenCurlyDoubleQuote]24s\[CloseCurlyDoubleQuote] over Twitter. \
Written in Wolfram Language because why not? \[LongDash] 2, 5, 5, 6 \
#24sTest"

Out[43]= 191
POSTED BY: Damanjit Singh
Posted 6 years ago
> In[39]:= (res[#]["Text"]) & /@ Range[res // Length]

Or using the All part specification

res[[All, "Text"]] // Normal
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract