com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links' is unknown.

Access Twitter's Search Using an API

Twitter API version 1.0 is retired from 11th June 2013 and the API version 1.1 cannot be accessed the way described in this sample

Introduction

This sample demonstrates how to subscribe to a published API and consume its functionality using the API Store Web application. The API used here provides search functionality in Twitter.

Prerequisites

  1. Execute the steps in Samples Setup. When you are done, you will have the API Manager started and the relevant scripts run to create user accounts for API Publisher and API Store.

Building the sample

  1. First, we need to add an API in the API Publisher and publish it to the API Store. To do that, simply run the APIPopulator.sh (for Linux) or APIPopulator.bat (for Windows) files from folder, <AM_HOME>/samples/TwitterSearch.
  2. The script will add an API to the API Publisher in Published state. This API can then be consumed by any user signed in to the API Store.

Executing the sample

Subscribing to the API

  1. Log in to the API Store (https://localhost:9443/store) with credentials subscriber1/subscriber1.
  2. Click the APIs tab at the top of the page and select the TwitterSearch API.
  3. Next, subscribe to this API. Simply select the default application and throttling tier as Gold.
  4. You will be asked to navigate to My Subscriptions tab.
  5. Next, generate a key to the application. You need this access key to invoke APIs subscribed under this application. Click on the Generate option in the box titled Production to obtain an Application key. For example,


    Invoking the API

  6. Once you have obtained a key, you can invoke the API using a REST client of your choice. In this example, we use cURL (http://curl.haxx.se).
  7. Copy and paste following into a new console window and execute it.

    curl -k -d "q=wso2&count=5" -H "Authorization :Bearer 9nEQnijLZ0Gi0gZ6a3pZICktVUca" https://localhost:8243/twitter/1.0.0/search.atom

    where, API key = 9nEQnijLZ0Gi0gZ6a3pZICktVUca. Replace this value with the API key you generated through the API Store in step 5 above.

    The <API Key> is passed in the Authorization header as a value of Bearer. The Authorization header of the message is prefixed by the string "Bearer". This is because, WSO2 API Manager enforces OAuth security on all the published APIs. Any consumer that talks to the API Manager should send their credential (application key) as per the OAuth bearer token profile. If you don't send an application key or send a wrong key, you will receive a 401 Unauthorized response in return

  8. You should be able to see search results from Twitter on your console. For example,

    <feed
    xmlns="http://www.w3.org/2005/Atom"
    xmlns:twitter="http://api.twitter.com/"
    xmlns:georss="http://www.georss.org/georss"
    xmlns:google="http://base.google.com/ns/1.0"
    xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/"
    xml:lang="en-US">
    <id>tag:search.twitter.com,2005:search/wso2</id>
    <link
    type="text/html"
    href="http://search.twitter.com/search?q=wso2"
    rel="alternate" />
    <link
    type="application/atom+xm..............
  9. Executing the above command several times with different API keys. Note the authentication failures returned by the API gateway when you pass invalid API keys. After a few invocations, the throttling policy of the API will get activated and the API gateway will start responding with 503 Service Unavailable response messages.

com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links2' is unknown.