Group Abstract Group Abstract

Message Boards Message Boards

[Mathematica-vs-R] Text analysis of Trump tweets

Posted 9 years ago
POSTED BY: Anton Antonov
5 Replies

Even if source parameter is not supported, you can quickly create you own utility to get what you want, e.g.

In[1]:= twitter = ServiceConnect["Twitter", "New"]
Out[1]= ServiceObject["Twitter", 
 "ID" -> "connection-29f751249df0b3e87a365f8c21a6b31f"]

In[20]:= url = 
  "https://api.twitter.com/1.1/statuses/user_timeline.json";

In[21]:= userid = Lookup[First@twitter["UserData"], "ID"];

(*build url with required paramaters*)
In[30]:= urlstring = 
  URLBuild[{url}, {"user_id" -> ToString@userid, 
    "screen_name" -> "realDonaldTrump", "count" -> 5}];

(*fetch data using authentication framework*)
In[31]:= result = OAuthClient`oauthdata[twitter, urlstring];

(*post processing result*)
In[33]:= data = ImportString[result[[2]], "RawJSON"];

In[34]:= #["source"] & /@ data
Out[34]= {
"<a href=\"http://twitter.com/download/iphone\" \rel=\"nofollow\">Twitter for iPhone</a>",
"<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter \for iPhone</a>",
"<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>",
"<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter \for iPhone</a>",
"<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>"
}
POSTED BY: Damanjit Singh

Dear Daman,

Thank you for your reply to Isaac!

Isaac, I was on a business trip and had limited time to deal with side projects... I hope Daman's answer works for you.

--Anton

POSTED BY: Anton Antonov

Thank you very much Daman!

Working with APIs is a first for me so this code is perfect for me to begin to understand the ideas behind creating the functionality that I need.

Once again I'm impressed by how short the code needs to be in Mathematica to get useful results.

enter image description here - another post of yours has been selected for the Staff Picks group, congratulations! We are happy to see you at the top of the "Featured Contributor" board. Thank you for your wonderful contributions, and please keep them coming!

POSTED BY: EDITORIAL BOARD
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard