Code covered by the BSD License  

Highlights from
twitty

5.0

5.0 | 1 rating Rate this file 49 Downloads (last 30 days) File Size: 18.4 KB File ID: #34837
image thumbnail

twitty

by Vladimir Bondarenko

 

30 Jan 2012 (Updated 24 Jun 2013)

Interface-class to access the Twitter REST API v1.1.

| Watch this File

File Information
Description

twitty is a MATLAB class for interaction with the twitter platform via its REST API v1.1.

Here are some examples of its usage:
tw = twitty(credentials); % create a twitty object and supply user credentials.

For details on credentials, type "help twitty" and refer to the sections about PROPERTIES and OBTAINING TWITTER CREDENTIALS.

After setting valid credentials, a twitty object should be able to access the Twitter platform. E.g.:

1. S = tw.search('matlab'); % search twitter.com for messages including the word 'matlab'.
2. S = tw.updateStatus('Hello, Twitter!'); % or twit something cooler.
3. S = tw.sampleStatuses(); % get a continuous stream of a random sample of all public statuses.
4. S = tw.userTimeline('screen_name', 'matlab'); % get recent messages posted by the user 'matlab';
5. S = tw.trendsAvailable(); % get place for which Twitter has trends available.

Conceptually, twitty methods are just wrapper functions around the main function which calls the Twitter API. This API caller function, callTwitterAPI(), does the main job:
creates an HTTPS request, handles the authentication and encoding, sends the request to and parses a response from the Twitter platform. It is not meant to be called directly but should be invoked
from a wrapper function.

The wrapper functions provide an intuitive MATLAB-style interface for accessing the Twitter's API resources. For the complete description of the REST API v1.1, refer to the official
documentation at https://dev.twitter.com/docs/api/1.1.
The API is quite extensive and twitty doesn't cover it all. It includes most of the resources in the following sections: TIMELINES, STREAMING, TWEETS, SEARCH, FRIENDS & FOLLOWERS, USERS, PLACES & GEO, TRENDS, and HELP.

For the summary of the twitty's methods run the 'twitty.API' command.
For information on a particular function, type 'help twitty.<function name>'.

REQUIREMENTS:
    optional - the json parser by Joel Feenstra: http://www.mathworks.co.uk/matlabcentral/fileexchange/20565-json-parser

Acknowledgements

Update Twitter Status and Json Parser inspired this file.

MATLAB release MATLAB 7.11 (R2010b)
Other requirements parse_json.m (optional)
Tags for This File  
Everyone's Tags
api, data import, twitter(2), web service
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (10)
02 Jul 2013 Saurabh Jha

it is not accepting query with or / and
for ex 'exascale or petascale'

Although twitter api supports this

Can some one help me on this?

04 May 2013 Jothi

Sir,

i have obtain twitter credential according to you instruction. ie.,

tw.saveCredentials()

but i have following error. how to set the credentials. how to search and download tweets using matlab.

??? Java exception occurred:
java.io.IOException: Server returned HTTP response code: 400 for URL:
http://api.twitter.com/1/account/verify_credentials.json

at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)

Error in ==> twitty>twitty.callTwitterAPI at 2018
inStream = BufferedReader( InputStreamReader( httpConn.getInputStream ) );

Error in ==> twitty>twitty.accountVerifyCredentials at 1410
S = twtr.callTwitterAPI(httpMethod,url,params,1);

Error in ==> twitty>twitty.saveCredentials at 233
S = twtr.accountVerifyCredentials;

kindly help me sir.

thanks in advance.

17 Aug 2012 Zachary

@Rucci

I added the following at line 1411:

if isstruct(S{1}), S = S{1}; end

Seems to fix the problem. Note: I have json_parser.m on my path.

26 Jul 2012 Rucci

Hello,
I've complete to obtain twitter credential according to your instruction.
I used my twitter credential to create the credential structure as the follows

credentials.ConsumerKey = 'XXXXXXXXXX';
credentials.ConsumerSecret = 'XXXXXXXXXXXXX';
credentials.AccessToken = 'XXXXXXXXXXXX';
credentials.AccessTokenSecret = 'XXXXXXXXXXXX';

Then I create the twitty object using the command: tw = twitty(credentials)
I got the error message as the follows

??? Error using ==> strfind
Inputs must be character arrays.

Error in ==> twitty>twitty.twitty at 149
if strfind(lower(S{1}),'error'), error('The supplied credentials are not
valid.'); end

I think the code had been modified since Apr 2012 for this problem. I'm not sure whether I did something wrong.

Would you please advise?

07 May 2012 Jose

I am trying to use the function friendshipsCreate and it gives me the following message...

>> S = tw.friendshipsCreate('pepe','matlab','follow','true')

??? Java exception occurred:
ice.net.URLNotFoundException: Document not found on server
at ice.net.HttpURLConnection.getInputStream(OEAB)

Error in ==> twitty>twitty.callTwitterAPI at 2018
inStream = BufferedReader( InputStreamReader(
httpConn.getInputStream ) );

Error in ==> twitty>twitty.friendshipsCreate at 1128
S =
twtr.callTwitterAPI(httpMethod,url,params,1);

26 Apr 2012 Vladimir Bondarenko

@Yu Ang Tan: thanks for the comment. I've fixed the strfind(lower(S),'error') issue.

@Justin: did it resolve your problem?

@Michael: I replied to your email, but my reply couldn't be delivered ("no such user" error). Do you have an alternative email address?

26 Apr 2012 Yu Ang Tan

Justin: change line 136:
if strfind(lower(S),'error'))...
to
if strfind(lower(S{1}),'error'))...

Michael: create a structure
credentials.ConsumerKey='SH1asd325tgdsasOVedYsA';
credentials.ConsumerSecret = 'on325gtgafafdsfegawe4365ghgSDF';
credentials.AccessToken = '123554-PZjoiso98n3ocrlWFOJ39rjlsjfwzOdq';
credentials.AccessTokenSecret = 'W6r324fjlajaMMLasffSMMk';
tw = twitty(credentials);

You'll need to replace those strings from your developer page. The strings above are just garbage values.

23 Apr 2012 Michael Antaran

Looks great. However, can you provide an example file format of how the credentials files should look like.

Sorry if this is a novice question. See potential but having difficult time using on 2007b.

thanks

15 Feb 2012 Justin

Not sure if I'm just doing something wrong but I can't seem to get this going. Whenever you try to set or save the credentials it returns an error

Conversion to logical from cell is not possible.

04 Feb 2012 Beaver

Disregard... I didn't read the twitter api suggestions. Great Code... Under promises, Over Delivers!!

Updates
26 Apr 2012

Some documentation updates.
Fixes: strfind(lower(S),'error') is changed to strfind(lower(S{1}),'error') in the constructor function, twitty().

24 May 2013

Updated to the Twitter REST API v1.1.
Added support for the Streaming API.

24 Jun 2013

Fixed: error in the constructor call twitty(creds), due to the outdated credentials validity check.

Contact us