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

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.

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

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

Hello @Anton Antonov

I've tried replicating your analysis using only the ServiceConnect framework without success. I'm interested in extracting the source field for a tweet, mentioned in the Twitter API site, but have had little success. Would you happen to know if this field can be extracted with the ServiceConnect framework?

Based on the documentation provided with Mathematica 11 and the links that you shared I've tried to obtain this information to no avail. I was hoping that executing the following code would provide me with at least an idea as to how the Request parameter is handled in Mathematica (hoping that maybe a parameter was not documented), but the results indicate that the source field is not recognized in the ServiceConnect framework (based on the column names shown in the output Dataset).

twitter = ServiceConnect["Twitter", "New"]    
tweets = twitter["TweetList", "Username" -> "realDonaldTrump", 
  "Elements" -> "FullData"]

Have you experimented in such a way with the ServiceConnect framework?

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