DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Code and Connect: MCP + MuleSoft
  • Phantom APIs Are Eating Your Attack Surface, and Most Security Teams Are Still Looking the Other Way
  • How to Set MX Records via API: Automate Email Routing Programmatically
  • I Reverse-Engineered 50 API Breaches. The Same Five Mistakes Keep Appearing.

Trending

  • From "Vibe Coding" to Production: Setting Up an Evals Loop for Claude Agents
  • The Invisible OOMKill: Why Your Java Pod Keeps Restarting in Kubernetes
  • A Hands-On ABAP RESTful Programming Model Guide
  • Building High‑Precision Vector Search for Document Retrieval on Databricks
  1. DZone
  2. Data Engineering
  3. Databases
  4. Calling YouTube API via Mule

Calling YouTube API via Mule

In this article, we will learn how to configure and call YouTube API in Mule with Google Cloud Platform (GCP) and a Mule flow.

By 
Karan Gupta user avatar
Karan Gupta
·
Mar. 01, 22 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
5.1K Views

Join the DZone community and get the full member experience.

Join For Free

To start developing API in Mule for this use case, we need to first create a project in Google Cloud Platform. So let us first complete the setup for it.

Setting Up Google Cloud Platform

  1. Log in to Google Cloud Platform using your credentials.GCP landing page
  2. Now we need to create a project and configure authentication to access it securely via REST API. We can use either OAuth client ID or API Key to secure our project access. For this, navigate to API and Services > Credentials > Create Credentials. GCP: Create credentials
  3. To make use of the API key, you just need to select the API key and you will be getting a key that you need to use to access your project.Selecting API key
  4. To make use of OAuth client ID follow the below steps.
    • Click on create OAuth Client ID. For the application type, select Web Application and also provide an APP Name. Then add the redirect URL http://localhost:8091/callback as shown below and click on save.Menu: Create OAuth client ID
    • You will receive the client ID and client secret. Keep these details handy as we will need it to configure in Mule Flow.OAuth client created — client ID and secret
    • Now navigate to API and Services > OAuth consent screen and edit the application you have created. Add the user support email and developer support email as those are mandatory fields and then click on save and continue for the rest of the steps.OAuth consent screen
    • Once done, publish the app for testing.Verification and publishing statuses
  5. The last step is to Enable YouTube Data API v3 from the library section for us to access YouTube APIs.Library: YouTube Data API v3

Creating Mule Application

Create a Mule flow and drag and drop an HTTP Listener and an HTTP Request component. Also, add OAuth Module from the exchange because we need to configure OAuth Authentication in HTTP Request.

HTTP Listener Configuration:

Keep the default host(0.0.0.0) and port(8081) configuration and set the path to /getChannelInfoHTTP listener configuration

HTTP Request Configuration

In the Request Configuration, set the protocol as HTTPS, the host as www.googleapis.com, and the port as 443.HTTP request configuration

Now scroll down in the configuration section and in the authentication drop-down select authorization code grant type. Set the details as shown below.authorization code grant type

We can now call YouTube Data API. For this use case, we will call the YouTube channel API that will provide your channel information like views count, number of videos, subscriber counts, etc. For this, set the path as /youtube/v3/channels. Also, we need to pass query parameters as seen below.Setting path as /youtube/v3/channels

The id in the above configuration is obtained from your YouTube channel link as seen below.YouTube channel content

Mule flow:youtubeapidemoFlow

Now run the code and hit the API via postman. Before hitting the actual API, we need to first hit the login API (http://localhost:8091/login) to generate the token as below.Message: successfully retrieved access token

Finally, the API call:

API call


API

Opinions expressed by DZone contributors are their own.

Related

  • Code and Connect: MCP + MuleSoft
  • Phantom APIs Are Eating Your Attack Surface, and Most Security Teams Are Still Looking the Other Way
  • How to Set MX Records via API: Automate Email Routing Programmatically
  • I Reverse-Engineered 50 API Breaches. The Same Five Mistakes Keep Appearing.

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook