Code covered by the BSD License  

Highlights from
twitty

5.0

5.0 | 5 ratings Rate this file 58 Downloads (last 30 days) File Size: 697 KB File ID: #34837
image thumbnail

twitty

by

 

30 Jan 2012 (Updated )

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   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (25)
21 Jul 2014 vicente torres

I got a msg of error:

??? Error using ==> twitty
Error: File: twitty.m Line: 448 Column: 33
Unexpected MATLAB operator.

I am using Matlab 7.8.
Can you help me? Thx

20 Jul 2014 Frederik

unfortunally i am facing the same problems as below:

Error using twitty (line 298)
The supplied credentials are not valid.

i made pretty sure, that i entered everything correctly.

Would appreciate to get some feedback, because i want to use this awesom function!

p.s. Using Matlab 2013a x64 with win 8

30 Jun 2014 Mircea Anghel

Hello.. I'm facing this error with tw.search('matlab'):

amazon = tw.search('matlab');
Error using twitty/callTwitterAPI (line 1975)
Java exception occurred:
java.io.IOException: Server returned HTTP response code: 401 for URL: https://api.twitter.com/1.1/search/tweets.json?q=matlab

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

at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)

Error in twitty/search (line 1065)
S = twtr.callTwitterAPI(httpMethod,url,params,1);

Any ideas How i can solve this?

Thanks

10 Jun 2014 Sujit Sahoo

I am also facing the same problem!
"Error using twitty (line 298)
The supplied credentials are not valid."

29 May 2014 Justin Baacke  
27 May 2014 Justin Baacke

I am having the same problem as Sean Mc was having with the
"Error using twitty (line 298)
The supplied credentials are not valid."
I was wondering what you worked out to fix it. I have checked my credentials on the twitter site via OAuth so I am fairly sure they are in fact valid but I was wondering if you had any other ideas as to where the problem might lie.

24 Mar 2014 Alfonso

This looks great!! I get the same error as SosoMed. I have not been able to make it work I am new to all this, sorry. Any advise??
Thanks in advance

28 Feb 2014 SosoMed

Trying "S = tw.search('matlab'); ",
But receive error:
">> try1
Error using twitty/callTwitterAPI (line 1974)
Java exception occurred:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path
building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to
find valid certification path to requested target

at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown Source)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(Unknown Source)

at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source)

at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source)

at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(Unknown Source)

at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(Unknown Source)

at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Unknown Source)

at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Unknown Source)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)

at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)

at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown
Source)

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

at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)

Caused by: sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid
certification path to requested target

at sun.security.validator.PKIXValidator.doBuild(Unknown Source)

at sun.security.validator.PKIXValidator.engineValidate(Unknown Source)

at sun.security.validator.Validator.validate(Unknown Source)

at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(Unknown Source)

at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown
Source)

at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown
Source)

... 12 more

Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find
valid certification path to requested target

at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source)

at java.security.cert.CertPathBuilder.build(Unknown Source)

... 18 more

Error in twitty/accountVerifyCredentials (line 1469)
S = twtr.callTwitterAPI(httpMethod,url,params,1);

Error in twitty/saveCredentials (line 398)
S = twtr.accountVerifyCredentials;

Error in try1 (line 3)
tw.saveCredentials();

>> try2
Error using twitty/callTwitterAPI (line 1974)
Java exception occurred:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX
path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable
to find valid certification path to requested target

at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown Source)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(Unknown Source)

at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source)

at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source)

at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(Unknown Source)

at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(Unknown Source)

at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Unknown Source)

at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Unknown Source)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown
Source)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)

at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)

at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown
Source)

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

at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)

Caused by: sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid
certification path to requested target

at sun.security.validator.PKIXValidator.doBuild(Unknown Source)

at sun.security.validator.PKIXValidator.engineValidate(Unknown Source)

at sun.security.validator.Validator.validate(Unknown Source)

at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(Unknown Source)

at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown
Source)

at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown
Source)

... 12 more

Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find
valid certification path to requested target

at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source)

at java.security.cert.CertPathBuilder.build(Unknown Source)

... 18 more

Error in twitty/search (line 1063)
S = twtr.callTwitterAPI(httpMethod,url,params,1);

Error in try2 (line 1)
S = tw.search('matlab');

06 Feb 2014 Sean Mc

Good stuff! And thanks for the debugging help!

05 Feb 2014 Sean Mc

Trying tw = twitty(credentials), but receive error, "The supplied credentials are not valid."
Have created twitter developer app successfully (tried twice).
MATLAB 8.1.0.604 (R2013a) on Win7 x64
Any suggestions?

03 Feb 2014 Arun Babu

Can anyone explain the procedure to get & include the "VeriSign Class 3 Public Primary Certification Authority - G5" certificate?

12 Dec 2013 Vladimir Bondarenko

From the 10th of Dec, api.twitter.com is using a new SSL certificate: https://dev.twitter.com/blog/rest-api-ssl-certificate-updates

Now, to establish a secure connection to Twitter, MATLAB must have in its keystore of trusted authorities the "VeriSign Class 3 Public Primary Certification Authority - G5" certificate.

11 Dec 2013 JJ

Works again in R2013b. Reason is the updated JVM (1.6 => 1.7) handling the TLS correctly.

I'm using http://www.mathworks.com/matlabcentral/fileexchange/33381-jsonlab-a-toolbox-to-encodedecode-json-files-in-matlaboctave as JSON parser, works flawlessly so far.

14 Jul 2013 Craig

This package has worked fantastic for me for automatic data updates. Thanks!

Recently I have had the same problem as Jothi below with the ERROR:

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

Any thoughts?

Thanks in advance,
Craig

11 Jul 2013 Trevor Cox

Code was just what I needed, thanks

"An output function can a usual m-file, e.g., the "tweetingSummary.m" file provided with the twitty"

Could you make tweetingSummary.m available to download?

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.

12 Jul 2013

Added auxiliary files: tweetingSummary.m and coastline.mat.

Contact us