We are super glad to announce that we are successfully integrated with YouTube!
Now, with just an API call including a YouTube link we will extract the metadata information from the video and give back to you the thumbnail, video title and description, and much more!
Extracting information from a YouTube link
First of all, enter your profile and copy your token. You will need it for the following steps :-)
We will be making a GET request to the following API endpoint:
https://api.opengraphr.com/v1/og
To make a request, you will need to include your api_token and the requested url:
GET https://api.opengraphr.com/v1/og?api_token={YOUR_API_TOKEN}&url={YOUR_URL}
By default, our API will cache results for a month, but you can refresh the cache by sending the force=1
parameter:
GET https://api.opengraphr.com/v1/og?api_token={YOUR_API_TOKEN}&url={YOUR_URL}&force=1
YouTube Metadata
Once the GET request is sent, you will get a response like this from our API. In this case, we are requesting the following URL: https://www.youtube.com/watch?v=hT_nvWreIhg
{
"title": "OneRepublic - Counting Stars (Official Music Video)",
"description": "Listen to OneRepublic's new single \"Wanted,\" out now: http://smarturl.it/Wanted1RShop OneRepublic: http://smarturl.it/1RShopSign up for email updates: http:/...",
"image": "https://i.ytimg.com/vi/hT_nvWreIhg/maxresdefault.jpg",
"url": "https://www.youtube.com/watch?v=hT_nvWreIhg",
"raw": {
"title": "OneRepublic - Counting Stars (Official Music Video) - YouTube",
"metadescription": "Listen to OneRepublic's new single \"Wanted,\" out now: http://smarturl.it/Wanted1RShop OneRepublic: http://smarturl.it/1RShopSign up for email updates: http:/...",
"og_site_name": "YouTube",
"og_url": "https://www.youtube.com/watch?v=hT_nvWreIhg",
"og_title": "OneRepublic - Counting Stars (Official Music Video)",
"og_image": "https://i.ytimg.com/vi/hT_nvWreIhg/maxresdefault.jpg",
"og_image_width": 1280,
"og_image_height": 720,
"og_description": "Listen to OneRepublic's new single \"Wanted,\" out now: http://smarturl.it/Wanted1RShop OneRepublic: http://smarturl.it/1RShopSign up for email updates: http:/...",
"og_type": "video.other",
"og_video_url": "https://www.youtube.com/embed/hT_nvWreIhg",
"og_video_secure_url": "https://www.youtube.com/embed/hT_nvWreIhg",
"og_video_type": "text/html",
"og_video_width": 1280,
"og_video_height": 720,
"og_video_tag": "onerepublic counting stars",
"twitter_card": "player",
"twitter_site": "@youtube",
"twitter_url": "https://www.youtube.com/watch?v=hT_nvWreIhg",
"twitter_title": "OneRepublic - Counting Stars (Official Music Video)",
"twitter_description": "Listen to OneRepublic's new single \"Wanted,\" out now: http://smarturl.it/Wanted1RShop OneRepublic: http://smarturl.it/1RShopSign up for email updates: http:/...",
"twitter_image": "https://i.ytimg.com/vi/hT_nvWreIhg/maxresdefault.jpg",
"twitter_app_name_iphone": "YouTube",
"twitter_app_id_iphone": 544007664,
"twitter_app_name_ipad": "YouTube",
"twitter_app_id_ipad": 544007664,
"twitter_app_url_iphone": "vnd.youtube://www.youtube.com/watch?v=hT_nvWreIhg&feature=applinks",
"twitter_app_url_ipad": "vnd.youtube://www.youtube.com/watch?v=hT_nvWreIhg&feature=applinks",
"twitter_app_name_googleplay": "YouTube",
"twitter_app_id_googleplay": "com.google.android.youtube",
"twitter_app_url_googleplay": "https://www.youtube.com/watch?v=hT_nvWreIhg",
"twitter_player": "https://www.youtube.com/embed/hT_nvWreIhg",
"twitter_player_width": 1280,
"twitter_player_height": 720
}
}
And that's it! Easy, right? 🤩 Now let's see some examples of how to implement this using actual code!
Extract YouTube information using PHP
You can easily get the Open Graph information of a given YouTube link by using the following script in PHP
$token = 'YOUR_TOKEN';
$url = 'https://www.youtube.com/watch?v=hT_nvWreIhg';
$requestUrl = 'https://api.opengraphr.com/v1/og?api_token=' . $token . '&url=' . urlencode($url);
$response = json_decode(file_get_contents($requestUrl), true);
var_dump($response);
Extract YouTube information using JavaScript
You can easily get the Open Graph information of a given YouTube URL by using the following script in plain JS:
const token = 'YOUR_TOKEN'
const url = 'https://www.youtube.com/watch?v=hT_nvWreIhg'
const requestUrl = `https://api.opengraphr.com/v1/og?api_token=${token}&url=${encodeURIComponent(url)}`
fetch(requestUrl)
.then(response => response.json())
.then(og => {
console.table(og)
})
Extract YouTube information using NodeJS
You can easily get the Open Graph information of a given YouTube URL by using the following script in NodeJS:
const axios = require('axios')
const express = require('express')
const app = express()
const token = 'YOUR_TOKEN'
app.get('/site/info', async (req, res) => {
const { url } = req.query
const requestUrl = 'https://api.opengraphr.com/v1/og'
const response = await axios.get(requestUrl, {
params: {
url,
api_token: token,
// force: 1,
},
})
const og = response.data
res.json(og)
})
app.listen(3000, function () {
console.log('Example app listening on port 3000!')
})
Extract YouTube information using C
You can easily get the Open Graph information of a given YouTube URL by using the following script in C-Sharp:
using System;
using System.Net;
using System.IO;
using Newtonsoft.Json;
namespace CSharpDemo
{
class MainClass
{
public static void Main (string[] args)
{
var token = 'YOUR_TOKEN';
var url = 'https://www.youtube.com/watch?v=hT_nvWreIhg';
var urlEncoded = Uri.EscapeDataString(url);
var requestUrl = "https://api.opengraphr.com/api/og?api_token=" + token + "&url=" + urlEncoded;
var request = WebRequest.Create(requestUrl);
request.ContentType = "application/json;";
string text;
var response = (HttpWebResponse)request.GetResponse();
using (var sr = new StreamReader(response.GetResponseStream()))
{
text = sr.ReadToEnd();
dynamic og = JsonConvert.DeserializeObject(text);
Console.WriteLine("Title\t\t" + og.title);
Console.WriteLine("Description\t" + og.description);
Console.WriteLine("Image\t\t" + og.image);
}
}
}
}
Extract YouTube information using Python
You can easily get the Open Graph information of a given YouTube URL by using the following script in Python:
import requests
TOKEN = 'YOUR_TOKEN'
url = 'https://www.youtube.com/watch?v=hT_nvWreIhg'
endpoint = 'https://api.opengraphr.com/api/og'
response = requests.get(endpoint, params={ 'url': url, 'api_token': TOKEN }).json()
print(response)