This documentation is for WSO2 API Manager 1.7.0 View documentation for the latest release.
Deploying and Testing YouTube API - API Manager 1.7.0 - WSO2 Documentation
||
Skip to end of metadata
Go to start of metadata

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 YouTube feeds.

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/YoutubeFeeds.

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 YoutubeFeeds 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, you can generate a key to the application. This key allows you to invoke APIs subscribed under a given application. Click on the Generate option 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 -H "Authorization :Bearer 9nEQnijLZ0Gi0gZ6a3pZICktVUca" http://localhost:8280/youtube/1.0.0/most_popular

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

The access token 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 results from YouTube on your console. For example,

<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns='http://www.w3.org/2005/Atom' xmlns:app='http://purl.org/atom/app#'
xmlns:media='http://search.yahoo.com/mrss/' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'
xmlns:gd='http://schemas.google.com/g/2005' xmlns:yt='http://gdata.youtube.com/schemas/2007'>
<id>http://gdata.youtube.com/feeds/api/standardfeeds/most_popular</id>
<updated>2012-07-26T04:51:52.363-07:00</updated>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>
<title type='text'>Most Popular</title>
<logo>http://www.youtube.com/img/pic_youtubelogo_123x63.gif</logo>
<link rel='alternate' type='text/html' href='http://www.youtube.com/browse?s=bzb'/>...

9. Access various other feeds in the YouTube API by changing the last segment of the invoked URL. For example,

curl -H "Authorization :Bearer 9nEQnijLZ0Gi0gZ6a3pZICktVUca" http://localhost:8280/youtube/1.0.0/top_rated
curl -H "Authorization :Bearer 9nEQnijLZ0Gi0gZ6a3pZICktVUca" http://localhost:8280/youtube/1.0.0/most_shared
curl -H "Authorization :Bearer 9nEQnijLZ0Gi0gZ6a3pZICktVUca" http://localhost:8280/youtube/1.0.0/most_viewed

Replace 9nEQnijLZ0Gi0gZ6a3pZICktVUca with the access token you generated through the API Store in step 5 above.

  • No labels