Access Twitter via Foswiki
In order to be able read information from twitter, you will need to grant access using an api key. Head over to
https://developer.twitter.com/en/apps, create an "app" and secure the required information into the plugin's configuration.
Syntax
%TWITTER{"<method>" [...parameters ...]}%
The plugin tries to make all parameters of the public twitter rest api available to wiki applications.
The most common ones are:
Parameter |
Description |
Default |
<method> |
known actions are - account_settings
- favorites
- friends
- folowers
- following_timeline
- retweets_of_me
- get_lists
- home_timeline
- list_statuses
- mentions_timeline
- rate_limit_status
- search
- user_timeline
... explained below. |
|
header="..." |
header string to be prepended to the timeline |
<ul class='twitter'> |
format="..." |
format string to be used for every tweet of a timeline |
<li class='tweet'>$avatar <span class='screen_name'>
<a href='$profile_url'>$name</a></span> - $time $retweet
<div class='text'>$text</div> $media
</li> |
separator="..." |
separator string between every tweet of a timeline being rendered |
|
footer="..." |
footer srting to be prepended to the timeline |
</ul> |
avatar_format |
string to render the user of a tweet, i.e. it's avatar |
<a class='avatar' href='$profile_url'><img src='$profile_image_url' height='48' width='48' title='$screen_name' /></a> |
retweet_format |
string to render a retweet differently |
<span class='retweet'>%MAKETEXT{"retweeted [_1]" args="<a href='https://twitter.com/$orig_screen_name'>$orig_screen_name</a>"}%</span> |
time_format |
string to render the tweet's time stamp |
<a href='$url' class='time'>$relative_created_at</a> |
photo_format |
this string is used to rendere a photo part of a tweet |
<a href='$display_url' class='photo'><img src='$url' width='$width' height='$height' /></a> |
raw="on/off" |
use this switch to return the raw json result of an action; all above format string won't be used then |
off |
count="<int>" |
number of tweets to return |
20 |
For additional parameters see
https://dev.twitter.com/rest/public.
Identifiers that can be used in a format string are:
-
$avatar
: expands to the result of the avatar_format
string
-
$time
: expands to the result of the time_format
string
-
$url
: status url
-
$profile_url
: link to the profile of the user that tweeted this status
-
$retweet
: expands to the result of the reteweet_format
-
$media
: expands to the result of the photo_format
string
-
$profile_image_url
: link to the user's avatar image
-
$text
: text of this tweet
-
$created_at
date when this tweet was created
-
$relative_created_at
-
$screen_name
: user's screen name
-
$name
: user's name
-
$orig_screen_name
: screen name of the user that created the original tweet
- =$orig_name: name of the user that created the original tweet
-
$id
: id of this tweet
Methods
TODO: this list is not complete yet. See additional methods at
Net::Twitter.
favorites
Returns the 20 most recent favorite statuses for the authenticating user or user specified by the ID parameter.
Parameters:
-
user_id
-
screen_name
-
count
-
since_id
-
max_id
-
include_entities
Example:
%TWITTER{"favorites"}%
folowers
Returns a list of users following the specified user.
Parameters:
Additional identifiers available when formatting results:
-
$created_at
-
$description
-
$favorites_count
-
$followers_count
-
$friends_count
-
$id
-
$lang
-
$listed_count
-
$location
-
$name
-
$profile_background_color
-
$profile_background_image_url
-
$profile_background_image_url_https
-
$profile_background_tile
-
$profile_image_url
-
$profile_image_url_https
-
$profile_link_color
-
$profile_location
-
$profile_sidebar_border_color
-
$profile_sidebar_fill_color
-
$profile_text_color
-
$profile_use_background_image
-
$protected
-
$screen_name
-
$status
-
$statuses_count
-
$time_zone
-
$url
-
$utc_offset
-
$verified
get_lists
Returns all lists the authenticating or specified user subscribes to, including their own. The user is specified using the user_id or screen_name parameters. If no user is given, the authenticating user is used.
Parameter:
-
user_id
-
screen_name
-
reverse
Additional identifiers available when formatting results
-
$id
-
$name
-
$slug
-
$mode
-
$subscriber_count
-
$member_count
-
$full_name
-
$description
Example:
%TWITTER{"get_lists"
id="<name>"
format=" * slug=$slug, id=$id"
separator="$n"
}%
home_timeline
Returns the 20 most recent statuses, including retweets, posted by the authenticating user and that user's friends.
Parameters:
-
since_id
-
max_id
-
count
-
exclude_replies
-
contributor_details
-
include_entities
-
trim_user
Example:
%TWITTER{
"home_timeline"
count="5"
}%
list_statuses
Returns tweet timeline for members of the specified list. Historically, retweets were not available in list timeline responses but you can now use the include_rts=true parameter to additionally receive retweet objects.
Parameters:
-
list_id
-
slug
-
owner_screen_name
-
owner_id
-
since_id
-
max_id
-
count
-
include_entities
-
include_rts
Example:
%TWITTER{
"list_statuses"
slug=<listname>"
owner_screen_name="<screen name>"
}%
mentions_timeline
Returns the 20 most recent mentions (statuses containing @username) for the authenticating user.
Parameters:
-
since_id
-
max_id
-
count
-
trim_user
-
include_entities
-
contributor_details
search
See also
https://dev.twitter.com/rest/public/search
Parameters:
-
q
(required)
-
count
-
lang
-
locale
-
rpp
-
since_id
-
max_id
-
until
-
geocode
-
include_entities
rate_limit_status
Returns the remaining number of API requests available to the authenticated user before the API limit is reached for the current 15 minutes window.
Additional identifiers available when formatting results:
*
$limit(<resource>)
*
$remaining(<resource>)
<resource>
is the name of the resource that a rate limit appies to. See
https://dev.twitter.com/rest/public/rate-limits for a list of available
resources.
Example:
%TWITTER{
"rate_limit_status"
format="| *Resource* | *Limit* | *Remaining* |
| /application/rate_limit_status | $limit(/application/rate_limit_status) | $remaining(/application/rate_limit_status) |
| /statuses/lookup | $limit(/statuses/lookup) | $remaining(/statuses/lookup) |
| /statuses/home_timeline | $limit(/statuses/home_timeline) | $remaining(/statuses/home_timeline) |
| /statuses/user_timeline | $limit(/statuses/user_timeline) | $remaining(/statuses/user_timeline) |
| /favorites/list | $limit(/favorites/list) | $remaining(/favorites/list) |
| /lists/list | $limit(/lists/list) | $remaining(/lists/list) |
| /lists/statuses | $limit(/lists/statuses) | $remaining(/lists/statuses) |
| /followers/list | $limit(/followers/list) | $remaining(/followers/list) |
| /search/tweets | $limit(/search/tweets) | $remaining(/search/tweets) |
"
}%
user_timeline
Returns the 20 most recent statuses posted by the authenticating user, or the user specified by screen_name or user_id.
Parameters:
-
user_id
-
screen_name
-
since_id
-
max_id
-
count
-
trim_user
-
exclude_replies
-
include_rts
-
contributor_details
Example:
%TWITTER{
"user_timeline"
id="<name>"
}%
Installation Instructions
First, you need to create a twitter app. Log in to your Twitter account and go to
https://apps.twitter.com/.
Click on "Create New App" and fill out the details, i.e. insert the URL of the new Foswiki website that you've
installed this plugin on. After clicking on "Create your Twitter application" you will get to a screen allowing
you to manage and configure details as required. Click on the "Keys and Access Tokens" tab
and collect the information needed to configure
TwitterPlugin using
configure
correctly
-
$Foswiki::cfg{TwitterPlugin}{APIKey}
-
$Foswiki::cfg{TwitterPlugin}{APISecret}
Next click on "Create my access token" and record these keys in:
-
$Foswiki::cfg{TwitterPlugin}{AccessToken}
-
$Foswiki::cfg{TwitterPlugin}{AccessSecret}
Make sure that you do NOT share this information with anybody else and that these keys are not readable
by unauthorized people inspecting the
LocalSite.cfg
file on your Foswiki server.
Dependencies
Name | Version | Description |
---|
Data::Dump | >=0 | Required. |
Net::Twitter | >=4.0 | Required. |
Foswiki::Contrib::CacheContrib | >=0 | Required. |
Change History