Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
http://www.tweet-sql.com
Version: 2.0
1
Contents
Introduction -4
Naming Conventions -4
Installing Tweet-SQL -5
Deploying Tweet-SQL Procedures -5
Removing Tweet-SQL Procedures -7
Configuring Tweet-SQL -9
Using Tweet-SQL - 10
Procedure Reference - 12
- tweet_sts_public_timeline - 12
- tweet_sts_friends_timeline - 12
- tweet_sts_user_timeline - 13
- tweet_sts_show - 13
- tweet_sts_update - 13
- tweet_sts_replies - 14
- tweet_sts_destroy - 14
- tweet_usr_featured - 14
- tweet_usr_friends - 14
- tweet_usr_followers - 15
- tweet_usr_show - 15
- tweet_msg_direct_messages - 16
- tweet_msg_sent - 16
- tweet_msg_new - 17
- tweet_msg_destroy - 17
- tweet_frd_create - 17
- tweet_frd_destroy - 17
- tweet_frd_exists - 17
- tweet_acc_archive - 18
- tweet_acc_verify_credentials - 18
- tweet_acc_end_session - 18
- tweet_acc_update_location - 18
- tweet_acc_update_delivery_device - 18
- tweet_acc_update_profile_colors - 18
- tweet_acc_update_profile - 19
- tweet_acc_rate_limit_status - 20
- tweet_fav_favourites - 20
- tweet_fav_create - 20
- tweet_not_follow - 21
- tweet_not_leave - 21
- tweet_blk_create - 21
- tweet_blk_destroy - 21
- tweet_hlp_test - 21
- tweet_hlp_downtime_schedule - 22
- tweet_util_shortenUrl - 22
- tweet_sog_followers - 22
- tweet_sog_friends - 22
- tweet_sog_followersTable - 23
- tweet_sog_friendsTable - 23
- tweet_cfg_loginDetails - 23
2
- tweet_cfg_http_request_timeout - 23
- tweet_cfg_resultset_send - 24
- tweet_cfg_no_type_array - 24
- tweet_cfg_licensekey - 25
Function Reference - 25
- tweet_fnc_dateconvert - 25
- tweet_fnc_httpformat - 25
- tweet_fnc_urlEncode - 25
3
Introduction
Tweet-SQL enables you to interact with the Twitter API with standard TSQL on Microsoft
SQL Server 2005 and above. With Tweet-SQL you can easily archive your timeline, send
direct messages to your followers, and of course, update your status. Leveraging the Twitter
API with Tweet-SQL is as easy as writing a few lines of TSQL. Be sure to check out the
example scripts on http://sqlclrnews.blogspot.com.
Naming conventions
All Tweet-SQL CLR procedures start with 'tweet_' and then a naming convention, indicating
their classification and function, according to the official twitter API documents.
http://apiwiki.twitter.com/REST+API+Documentation
For example all Tweet-SQL procedures implementing the 'status' methods start with
'tweet_sts_'.
4
leave Notification tweet_not_leave
create Block tweet_blk_create
destroy Block tweet_blk_destroy
test Help tweet_hlp_test
downtime_schedule Help tweet_hlp_downtime_schedule *
ids (followers) Social Graph tweet_sog_followers
ids (friends) Social Graph tweet_sog_friends
ids (followers) Social Graph tweet_sog_followersTable
ids (friends) Social Graph tweet_sog_friendsTable
* Procedures for Twitter depreciated API methods. These may cease to function at any time.
Do not use in new projects.
There are also a number of procedures you can use to configure Tweet-SQL inside TSQL
scripts. These use the naming convention of "tweet_cfg_<function>".
Installing Tweet-SQL
Tweet-SQL should be installed on the SQL Server you intend to use the procedures on.
Please ensure you install Tweet-SQL under an administrator account. To install double click
the "Tweet-SQL Setup.msi" file and follow the on screen instructions.
After installing Tweet-SQL the procedures need to be deployed to a local SQL Server
instance and the settings configured.
5
• Click "Deploy"
• Choose a Local SQL Server instance to log on to.
• Choose Windows or SQL Server Authentication (enter a valid SQL Server login) and
click "Connect".
• In the next screen choose or database to install Tweet-SQL in. (You may also create a
new database if you wish.)
• Click "Next".
6
• Click "Install" to deploy Tweet-SQL. This may take a few moments.
7
• Click "Connect"
• Select the database to remove Tweet-SQL from.
N.B. By checking "Also Disable SQL CLR" all CLR functionality on the SQL Server will be
disabled.
• Click "Next".
• Click "Remove".
8
• Click "Finish" to exit this window.
Configuring Tweet-SQL
Tweet-SQL can be configured through the Tweet-SQL Configuration program, included in
the installation, or through the provided Stored Procedures.
The following stored procedures are available to adjust the settings of Tweet-SQL.
9
Using Tweet-SQL
Tweet-SQL uses XML output variables to provide flexibility in how Twitter data can be
handled. You can instead use the various settings available in Tweet-SQL to return
differently formatted resultsets but a null output parameter needs to be included. The Tweet-
SQL examples shown here have been executed in SQL Server Management Studio (SSMS).
First run the Tweet-SQL Configuration Program and ensure the "Result Type" is set to "No
ResultSets". Run the below T-SQL in SSMS...
SSMS will display a nicely formatted XML document if you click on the blue hyper-linked
resultset returned by Tweet-SQL.
Next go back to the Tweet-SQL Configuration Program and change "Result Type" to
"Relational Resultsets". Execute the below T-SQL in SSMS...
10
Note: The public timeline will include an extra resultset if you do not choose to omit it. This
is the "type array" returned by twitter and displayed by Tweet-SQL like below.
Please note that Tweet-SQL may return more than one resultset depending on the call made.
Consult your programming language's documentation for information on how to deal with
multiple resultsets in a single call. Hint: ADO.Net has the NextRecordSet() method, the PHP
extension PDO_ODBC has the nextRowset() method, while Java has the getMoreResults()
method.
11
Procedure Reference
tweet_sts_public_timeline - @xml OUTPUT
Returns the 20 most recent statuses from non-protected users who have set a custom user
icon. Does not require authentication. Note that the public timeline is cached for 60 seconds
so requesting it more often than that is a waste of resources. The API limit is not applicable
for the public timeline method.
Returns the 20 most recent statuses posted by the authenticating user and that user's friends.
This is the equivalent of /home on the Web. API usage consumes 1 for each request.
Basic usage;
The @optional parameter can be used for multiple twitter parameters each with a different
functions.
• since. Optional. Narrows the returned results to just those statuses created after the
specified HTTP-formatted date, up to 24 hours old. The same behaviour is available
by setting an If-Modified-Since header in your HTTP request.
• since_id. Optional. Returns only statuses with an ID greater than (that is, more
recent than) the specified ID.
• count. Optional. Specifies the number of statuses to retrieve. May not be greater
than 200.
12
EXEC dbo.tweet_sts_friends_timeline '?page=3', null;
Returns the 20 most recent statuses posted from the authenticating user. It's also possible to
request another user's timeline via the @user_id_or_nick parameter. This is the equivalent of
the Web /archive page for your own user, or the profile page for a third party.
Basic usage.
• count. Optional. Specifies the number of statuses to retrieve. May not be greater than
200.
-- Returns the last 200 statuses from the authenticating users timeline
EXEC dbo.tweet_sts_user_timeline null, '?count=200', null;
• since. Optional. Narrows the returned results to just those statuses created after the
specified HTTP-formatted date, up to 24 hours old.
-- Returns the statuses since the http formatted date, up to 24 hours old
EXEC dbo.tweet_sts_user_timeline null, '?since=Sat%2C+25+Oct+2008+00%3A55%3A48+GMT', null;
• since_id. Optional. Returns only statuses with an ID greater than (that is, more recent
than) the specified ID.
13
Returns the 20 most recent @replies (status updates prefixed with @username) for the
authenticating user.
Basic usage.
• since. Optional. Narrows the returned results to just those replies created after the
specified HTTP-formatted date, up to 24 hours old.
• since_id. Optional. Returns only statuses with an ID greater than (that is, more
recent than) the specified ID.
Destroys the status specified by the required status_id parameter. The authenticating user
must be the author of the specified status.
This procedure is deprecated and may cease to function at any time. Do not use in new
projects.
Returns up to 100 of the authenticating user's friends who have most recently updated, each
with current status inline. It's also possible to request another user's recent friends list via the
user_id_or_nick parameter.
14
Usage with the @optional parameter.
• since. Optional. Narrows the returned results to just those friendships created after
the specified HTTP-formatted date, up to 24 hours old. The same behaviour is
available by setting an If-Modified-Since header in your HTTP request.
Returns the authenticating user's followers, each with current status inline.
Returns extended information of a given user, specified by ID or screen name as per the
required user_id_or_nick parameter. You must be properly authenticated to request the page
of a protected user.
Basic usage.
or
15
tweet_msg_direct_messages - @optional INPUT, @xml OUTPUT
Returns a list of the 20 most recent direct messages sent to the authenticating user.
Basic usage.
• since. Optional. Narrows the resulting list of direct messages to just those sent after
the specified HTTP-formatted date, up to 24 hours old.
EXEC dbo.tweet_msg_direct_messages
'?since=Sat%2C+11+Oct+2008+00%3A55%3A48+GMT', null;
• since_id. Optional. Returns only direct messages with an ID greater than (that is,
more recent than) the specified ID.
Returns a list of the 20 most recent direct messages sent by the authenticating user.
Basic usage.
• since. Optional. Narrows the resulting list of direct messages to just those sent after
the specified HTTP-formatted date, up to 24 hours old.
• since_id. Optional. Returns only sent direct messages with an ID greater than (that is,
more recent than) the specified ID.
• page. Optional. Retrieves the 20 next most recent direct messages sent.
16
Sends a new direct message to the specified user from the authenticating user. Requires the
user_id_or_nick, message and xml parameters below. Returns the sent message when
successful.
Destroys the direct message specified in the required ID parameter. The authenticating user
must be the recipient of the specified direct message. The deleted message is returned when
successful.
Befriends the user specified in the ID parameter as the authenticating user. Returns the
befriended user when successful.
Basic usage.
Discontinues friendship with the user specified in the ID parameter as the authenticating user.
Returns the un-friended user in the requested format when successful.
Basic usage.
Basic usage.
17
This procedure is deprecated and may cease to function at any time. Do not use in new
projects.
Use this procedure to test if supplied user credentials are valid with minimal overhead.
Returns user information for the authenticating credentials.
Basic usage.
Basic uage.
EXEC dbo.tweet_acc_end_session;
Basic usage.
Sets which device Twitter delivers updates to for the authenticating user. Sending none as
the device parameter will disable IM or SMS updates. The @device parameter must be one of
'sms', 'im' or 'none'.
Basic usage.
Controls the colour scheme of the authenticating user’s profile. Each parameter's value must
be a valid hexadecimal value, and may be either three or six characters (ex: #fff or #ffffff). At
18
least one colour value must be supplied when the procedure is called. If a null value is
entered for a parameter then the procedure will not attempt to update the corresponding
colour value.
Basic usage.
Updates values editable on the Twitter website under the ‘Account’ tab. If a null value is
entered for a parameter then the procedure will not attempt to update the corresponding
colour value, i.e. Supplying “Joe Bloggs” for the name and NULL for the remaining values
will not change any value other than name. The remove the contents of a field you must
specify a space character.
Basic Usage.
19
null,
null,
@description,
null;
Returns the remaining number of API requests available to the authenticating user before the
API limit is reached for the current hour. Calls to rate_limit_status will not count against the
rate limit.
Basic usage.
Returns the 20 most recent favorite statuses for the authenticating user or user specified by
the user_id_or_nick parameter.
Basic usage.
Favourites the status specified in the ID parameter as the authenticating user. Returns the
favourite status when successful.
Basic usage.
20
Enables notifications for updates from the specified user to the authenticating user. Returns
the specified user when successful. You must already be friends with a user to use this action
otherwise an error is returned.
Basic usage.
Disables notifications for updates from the specified user to the authenticating user. Returns
the specified user when successful. You must already be friends with a user to use this action
otherwise an error is returned.
Basic usage.
Blocks the user specified in the user_id_or_nick parameter as the authenticating user.
Returns the blocked user in the requested format when successful.
Basic usage.
Un-blocks the user specified in the user_id_or_nick parameter as the authenticating user.
Returns the un-blocked user in the requested format when successful.
Basic usage.
Basic usage.
21
This procedure is deprecated and may cease to function at any time. Do not use in new
projects.
Returns a TinyURL for the @long_url value or null upon failure. No attempt will be made to
shorten urls less than 30 characters and the procedure will return the @long_url value for
@short_url.
Basic usage.
SELECT @short_url;
Returns the ids of the authenticating users followers or, if a non-null value is supplied for
@user_id_or_nick, the ids of the specified user’s followers.
Basic usage.
Returns the ids of the authenticating users friends or, if a non-null value is supplied for
@user_id_or_nick, the ids of the specified user’s friends.
Basic usage.
22
tweet_sog_followersTable - @user_id_or_nick INPUT
Returns the same data from tweet_sog_followers but saves it to a table in the SQL Server
database Tweet-SQL is hosted in. The table created is called tweet_followersIds. Any
existing table with this name is dropped at the start of the procedure execution.
Basic usage.
Returns the same data from tweet_sog_friends but saves it to a table in the SQL Server
database Tweet-SQL is hosted in. The table created is called tweet_friendsIds. Any existing
table with this name is dropped at the start of the procedure execution.
Basic usage.
Basic usage.
This procedure allows you to adjust the default http request timeout used by Tweet-SQL.
Please note the timeout value is expressed as milliseconds.
Basic usage.
23
EXEC dbo.tweet_cfg_http_request_timeout 30000;
This procedure allows you to modify the way results are returned by Tweet-SQL. The
resultset_send parameter allows values of 0, 1 and 2 only.
Basic usage.
This procedure will return some help if you enter an invalid value for @resultset_send
This procedure allows you to include, or omit, the "type array" returned by twitter for some
method calls. The @no_type_array parameter will only accept values of 0 or 1, returning help
text otherwise.
Basic usage.
This procedure will return some help if you enter an invalid value for @no_type_array.
24
The no_type_array parameter must be one of the following values...
0 : The type array table is returned with the resultset(s).
1 : The type array table is omitted from the resultset(s).
This procedure allows you to update the license key used for Tweet-SQL.
Basic usage.
Function Reference
tweet_fnc_dateconvert - @httpDateTime
This function is for transforming Twitter returned http formatted datetime strings into
something more suitable for SQL Server. The function will attempt to return a OBDC
canonical formatted datetime value for the provided input and will return NULL upon failure.
Basic usage.
tweet_fnc_httpformat - @datetime
This function is for converting datetime values into their http formatted equivalents. NULL is
returned on failure.
Basic usage.
SELECT dbo.tweet_fnc_httpformat(GETDATE());.
tweet_fnc_urlEncode - @query
This function url encodes user inputted strings. NULL is returned on failure.
Basic usage.
25