Analytics/CMS APIs Sample: Recently Added Videos

Product(s)
Video Cloud
Role(s)
API Developer
Topic(s)
Analytics
Code Samples
API(s)
Analytics API
CMS API

In this sample, you will learn how to get Analytics data for videos that have been added to Video Cloud over some recent period (which you define in the inputs). Note that this app only returns reports on a single dimension, though it could be modified to report on multiple dimensions.

APIs used

This sample uses two Brightcove APIs:

  • CMS API (to find recently added videos)
  • Analytics API (to get the analytics)

Getting Credentials

To get a client_id and client_secret, you will need to go to the OAuth UI and register this app:

These are the permissions you will need:

Analytics API Permissions
Analytics API Permissions

You can also get your credentials via CURL or Postman - see:

If you are getting credentials directly from the API, these are the permissions you need:

    [
      "video-cloud/analytics/read",
      "video-cloud/video/read"
    ]

CodePen

Find all the code associated with this sample in this GitHub repository.

See the Pen Analytics/CMS APIs Sample: Recently Added Videos by Brightcove Learning Services (@rcrooks1969) on CodePen.

Using the CodePen

Here are some tips to effectively use the above CodePen:

  • Toggle the actual display of the player by clicking the Result button.
  • Click the HTML/CSS/JS buttons to display ONE of the code types.
  • Click Edit on CodePen in the upper right corner to fork this CodePen into your own account.
  • Find all the code associated with this sample in this GitHub repository.

Code

There are four parts to the app:

  • The HTML
  • A data model for the Analytics API (this data could have just been created in the JavaScript, but I already had the model for other purposes)
  • The JavaScript
  • The proxy (gets access tokens and makes the API requests - written in PHP, but any server-side language will do)

You can view the HTML and main JavaScript in the CodePen above. The data model and information on the proxy are shown below.

Proxy code

In order to build your own version the sample app on this page, you must create and host your own proxy. (The proxies used by Brightcove Learning Services only accept requests from Brightcove domains.) A sample proxy, very similar to the one we use, but without the checks that block requests from non-Brightcove domains, can be found in this GitHub repository. You will also find basic instructions for using it there, and a more elaborate guide to building apps around the proxy in Using the REST APIs.