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

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Enterprise AI Trend Report: Gain insights on ethical AI, MLOps, generative AI, large language models, and much more.

2024 Cloud survey: Share your insights on microservices, containers, K8s, CI/CD, and DevOps (+ enter a $750 raffle!) for our Trend Reports.

PostgreSQL: Learn about the open-source RDBMS' advanced capabilities, core components, common commands and functions, and general DBA tasks.

AI Automation Essentials. Check out the latest Refcard on all things AI automation, including model training, data security, and more.

Related

  • Securing Cloud Storage Access: Approach to Limiting Document Access Attempts
  • How to Query XML Files Using APIs in Java
  • API Governance: Ensuring Control and Compliance in the Era of Digital Transformation
  • API Appliance for Extreme Agility and Simplicity

Trending

  • Harmonizing AI: Crafting Personalized Song Suggestions
  • Deploying to Heroku With GitLab CI/CD
  • C4 PlantUML: Effortless Software Documentation
  • Code Complexity in Practice
  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
Like (4)
Save
Tweet
Share
4.6K 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

  • Securing Cloud Storage Access: Approach to Limiting Document Access Attempts
  • How to Query XML Files Using APIs in Java
  • API Governance: Ensuring Control and Compliance in the Era of Digital Transformation
  • API Appliance for Extreme Agility and Simplicity

Partner Resources


Comments

ABOUT US

  • About DZone
  • Send feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: