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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Google Cloud Pub/Sub vs. AWS SNS and SQS: One Java API for Both With MultiCloudJ
  • Passwordless Image Pulls in Kubernetes With ServiceAccount Tokens and a Credential Provider
  • Zero Trust for Agents: A New Lens to Secure Agents
  • Reusable Operational Playbooks With Agent Skills

Trending

  • Function Calling: Responses API vs Chat Completions
  • Bolting an LLM Onto a System That Can't Afford to Be Wrong
  • Using LLMs to Generate Unit Tests and Review Pull Requests in Spring Boot
  • Crash-Proof Agents: Durable Execution for Long-Running AI Systems

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
·
Mar. 01, 22 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
5.3K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

  • Google Cloud Pub/Sub vs. AWS SNS and SQS: One Java API for Both With MultiCloudJ
  • Passwordless Image Pulls in Kubernetes With ServiceAccount Tokens and a Credential Provider
  • Zero Trust for Agents: A New Lens to Secure Agents
  • Reusable Operational Playbooks With Agent Skills

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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