Skip to content
haschek edited this page Sep 13, 2012 · 1 revision

Twitter service class

This service integrates users status streams and a keyword searches from Twitter within your PubwichFork page.

Installation: add your Twitter application

Before you can use the Twitter service class you need to create a new Twitter application because the service class is using Twitter's OAuth authentification to request data. It's easy to create it:

  1. Go to https://dev.twitter.com/apps/ and create a new application
  2. Fill out the data:
  1. save it
  2. Request the Access Token at the bottom of the details page

Now you can copy the necessary keys, tokens and secrets to configure the Twitter service class.

Configuration values

  • method: either TwitterUser or TwitterSearch
  • oauth: an php array with values for following keys: app_consumer_key, app_consumer_secret, user_access_token and user_access_token_secret

... and all basic options of services.

for TwitterUser

  • username: the users name on Twitter, taken from https://twitter.com/username

for TwitterSearch

  • terms: keyword phrase you want search for

Example configuration

$twitter_pf = array(
    'Twitter', 'twitter_pf', array(
		'method' => 'TwitterSearch',
		'terms' => 'PubwichFork',
		'oauth' => array(
			'app_consumer_key' => 'YOUR_APP_CONSUMER_KEY_STRING',
			'app_consumer_secret' => 'YOUR_APP_CONSUMER_SECRET_STRING',
			'user_access_token' => 'YOUR_USER_ACCESS_TOKEN_STRING',
			'user_access_token_secret' => 'YOUR_USER_ACCESS_TOKEN_SECRET_STRING'
		),
		'total' => 5,
		'title' => 'Twitter',
		'description' => 'PubwichFork search'
	)
);

Template keys

  • text: the original text withouth any links
  • status: the text with link replacements for @username, #hashtag and URL strings
  • date: date of the tweet
  • link: permanent URL of the status tweet
  • user_name: full name of the user who tweeted
  • user_nickname: short name of the user who tweeted, like in https://twitter.com/shortname
  • user_link: permanent URL of the user
  • user_image: thumbnail image of the user

Example template

function TwitterSearch_itemTemplate() {
    return '<li>
                <a href="{{{user_link}}}"><img class="item-media-thumbnail" width="48" height="48" src="{{{user_image}}}" alt="" />
                <strong>@{{{user_nickname}}}</strong></a>:
                {{{status}}}
                (<a href="{{{link}}}">{{{date}}}</a>)
            </li>'.PHP_EOL;
}