Project:Twitter feeds

From SpinetiX Support Wiki

(Redirected from Using Twitter feeds)
Jump to: navigation, search

Introduction

The two sample projects present on this page can be used to display Twitter API v1.1 feeds , once you've created a Twitter application and added the authorization info (see details below).

Note: The previous projects using Twitter API v1 are no longer working due to Twitter API v1 retirement.

Twitter Project (using API v1.1)

Specifications

  • Category: Data feeds
  • Author: SpinetiX S.A.
  • License: GPL Version 3
  • Target: Elementi
  • Version: 4.3 (last modification date: 2014-06-11)

Description

Twitter provides various feeds, however you need to be authenticated on the Twitter website, before being able to access these feeds. In a similar manner, to display these feeds on the HMP, you need to authorize the HMP to access the Twitter API v1.1 data on your behalf - and this is done by creating a Twitter application. After that, you can use the Twitter Project below to display Twitter data.

The Twitter Project contains four "Twitter {layout}.svg" files (e.g., "Twitter Slideshow.svg", "Twitter Table.svg", "Twitter Text Bar.svg" and "Twitter Text Ticker.svg") responsible for the data layout and two JS files ("oauth.js" and "twitter.js") responsible for authentication and data retrieval. The index.svg files includes by default the "Twitter Text Ticker.svg" file.

Configuration

Add the authorization info

In order to display any information from Twitter, edit the "Twitter {layout}.svg" file you are using and replace the "XXXXXXXXXXXXXXXX" strings in the code below by the real OAuth settings of your application.

var oauth = new OAuth( {
        consumer_key : "XXXXXXXXXXXXXXXX",
        consumer_secret : "XXXXXXXXXXXXXXXX",
        access_token : "XXXXXXXXXXXXXXXX",
        access_token_secret : "XXXXXXXXXXXXXXXX"
      });

Note Note: Be aware that Twitter imposes some rate limits on the amount of data that can be retrieved every 15 minutes. As this example do not use caching, make sure that the document is not re-opened more frequently than once per minute. If you are only using the statuses (or the search) then the limits are higher. Additionally, if you have multiple players using the same application OAuth settings, then the refresh rate should be proportionally increased.

Set the API call URI

To configure what tweets to be retrieved and displayed, you need to edit the "Twitter {layout}.svg" file you are using and set the parameters of the get_uri function as explained in the "Supported tweets" section below.

var uri = oauth.get_uri(  uri, 
                          array_of_parameters
                        );

Most of the Twitter API calls are supported by this sample project (see the supported tweets below). See REST API v1.1 Resources for the complete list of API calls that are possible.

Supported tweets

User tweets

To retrieve all the tweets (the timeline) from 'spinetix' use the following configuration:

var uri = oauth.get_uri(  'https://api.twitter.com/1.1/statuses/user_timeline.json', 
                          { 
                            screen_name : 'spinetix',
                            count : 10,
                            include_rts : true
                          }
                        );

Home Timeline

To retrieve the most recent Tweets and re-tweets posted by the user associated with the application and the followed users. See home timeline for more.

var uri = oauth.get_uri(  'https://api.twitter.com/1.1/statuses/home_timeline.json', 
                          { 
                            count : 12,
                            include_entities : true
                          }
                        );

Favorite tweets

To retrieve all the favorite tweets from the user 'mh4k' use the following configuration:

var uri = oauth.get_uri(  'https://api.twitter.com/1.1/favorites/list.json', 
                          { 
                            screen_name : 'mh4k',
                            count : 12,
                            include_entities: true
                          }
                        );

Using search

It is also possible to use Twitter search. For instance to find all the tweets happening in #Wimbledon or #rolandgarros use the following configuration:

var uri = oauth.get_uri(  'https://api.twitter.com/1.1/search/tweets.json', 
                          { 
                            q : '#Wimbledon OR #rolandgarros',
                            result_type : 'recent'
                          }
                        );

Followers

To display the list of followers of an users, you can use the following:

var uri = oauth.get_uri(  'https://api.twitter.com/1.1/followers/list.json', 
                          { 
                            screen_name  : 'spinetix'                            
                          }
                        );

Data layout

The file twitter.js uses a custom parser to convert the answer from Twitter API to an array.

The following columns are created:

  • [[name]]
    current user name (e.g. Twitter API).
  • [[screen_name]]
    current user screen name (e.g. twitterapi).
  • [[profile_image_url]]
    current user thumbnails.
  • [[retweet]]
    Set to 1 is this is a re-tweet.
  • [[name_tweet]]
    User name of the user that posted the tweet. Different than [[name]] for the case of re-tweets.
  • [[screen_name_tweet]]
    Screen name of the user that posted the tweet.
  • [[profile_image_url_tweet]]
    Thumbnails of the user that posted the tweet.
  • [[tweet_time]]
    Date of the tweet.
  • [[tweet_id]]
    ID of the tweet.
  • [[text]]
    Cleaned tweet text (url have been removed).
  • [[text_link]]
    Tweet text with full URL.
  • [[text_raw]]
    Original tweet text.
  • [[media_url]]
    URL of the media present in the tweet.
  • [[has_media]]
    Set to 1 if a media is present.

HMD Twitter Project (using API v1.1)

Specifications

  • Category: Data feeds
  • Author: SpinetiX S.A.
  • License: GPL Version 3
  • Target: HMD

Description

Twitter provides various feeds, however you need to be authenticated on the Twitter website, before being able to access these feeds. In a similar manner, to display these feeds on the HMP, you need to authorize the HMP to access the Twitter API v1.1 data on your behalf - and this is done by creating a Twitter application. After that, you can use the Twitter Project below to display Twitter data.

The Twitter Project for HMD contains two files: "twitter news.svg" and "twitter news_ticker.svg" responsible for the data layout and two JS files ("oauth.js" and "twitter.js") responsible for authentication and data retrieval. The index.svg files includes both files by default.

Dues to the authentication mechanism, the "twitter news.svg" and "twitter news_ticker.svg" files do not use any form of caching. Thus the list of feeds are created when opening the document and never updated, unless the document is re-opened.

Configuration

Add the authorization info

In order to display any information from Twitter, edit the "twitter news.svg" or "twitter news_ticker.svg" file you are using and replace the "XXXXXXXXXXXXXXXX" strings in the code below by the real OAuth settings of your application.

var oauth = new OAuth( {
        consumer_key : "XXXXXXXXXXXXXXXX",
        consumer_secret : "XXXXXXXXXXXXXXXX",
        access_token : "XXXXXXXXXXXXXXXX",
        access_token_secret : "XXXXXXXXXXXXXXXX"
      });

Note Note: Be aware that Twitter imposes some rate limits on the amount of data that can be retrieved every 15 minutes. As this example do not use caching, make sure that the document is not re-opened more frequently than once per minute. If you are only using the statuses (or the search) then the limits are higher. Additionally, if you have multiple players using the same application OAuth settings, then the refresh rate should be proportionally increased.

Set the API call URI

To configure what tweets to be retrieved and displayed, you need to edit the "Twitter {layout}.svg" file you are using and set the parameters of the get_uri function as explained in the Supported tweets section above.

uri = oauth.get_uri(  uri, 
                          array_of_parameters
                        );

Most of the Twitter API calls are supported by this sample project (see the supported tweets below). See REST API v1.1 Resources for the complete list of API calls that are possible.

Data layout

The layout of the data is controlled by the same columns as in Project:Twitter_feeds#Data_layout, expect that the HMD news templates syntax should be used, i.e. [SPX][name] for the current user name (e.g. Twitter API).

Creating a Twitter application

To create a Twitter application that is authorized to access Twitter data on your behalf, follow these steps:

  1. Go to https://apps.twitter.com/ (or https://dev.twitter.com/user/login?destination=apps).
  2. Log in using your Twitter account. You should be redirected to the "apps" page, if this is not the case, select "My applications" in the top-right drop-down menu.
  3. Create a new application.
  4. Enter the required application details (name, description, website). You can skip the Callback URL field.
  5. Agree with the Twitter conditions and press the "Create ..." button.
  6. Once the application is created, go to "API Keys" section. At this point you should see the API key and API secret strings.
  7. Further down the page, find and press the "Create my access token" button. (This enables the application to use your account to access Twitter data.)
  8. Press the "Test OAuth" button.
  9. Write down the OAuth settings: Consumer key, Consumer secret, Access token and Access token secret.
This page was last modified on 20 November 2014, at 13:54.