Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google / Youtube Api (v3) - verify the owner of a video

Context:
I'm building a website using Symfony2 (php) and I have already implemented a social(google) login function (through HWIOAuthBundle) that allows users to:
- register a new account using their own google account
- link a google account to an existing non-social account
As a result, in my database the users table already has a google_id field.

What I want to do:
Users must be able to submit youtube links of their own videos. These links will be saved in the database BUT first I need to verify that the video BELONGS(IS OWNED) to the user that is submitting the link. In other words: users CAN NOT submit videos uploaded by someone else.
I plan on using the Youtube API (php) that you can find on the google developers website.

Question(s):
How can I verify this condition? Can I use the Google Id that I already have in my users table? Or do I need to create a new youtube_id field because the id is different from the google_id? What api function/method should I call to verify the video ownership?
Ideas?

like image 768
Igor Carmagna Avatar asked Dec 10 '15 08:12

Igor Carmagna


People also ask

How do you find out who owns a video on YouTube?

You may do a Google search, use Wayback Machine, search Twitter and use the video thumbnail URL to find the owner of a private YouTube video. When an owner of a YouTube video makes it private, he or she wants to limit the number of people who can watch the video.

How do I get YouTube data v3 API?

Log in to Google Developers Console. Create a new project. On the new project dashboard, click Explore & Enable APIs. In the library, navigate to YouTube Data API v3 under YouTube APIs.

What is content owner ID?

Content ID is YouTube's automated, scalable system that enables copyright owners to identify YouTube videos that include content they own. YouTube only grants Content ID to copyright owners who meet specific criteria.


1 Answers

Try to check them by v3/videos - https://developers.google.com/youtube/v3/docs/videos/list

if you use "part=snippet" you will see channel info in items->snippet->channelId and items->snippet->channelTitle

For example for https://www.youtube.com/watch?v=YVe2THgSDxc load

https://www.googleapis.com/youtube/v3/videos?id=YVe2THgSDxc&part=snippet&key=[YOUR_API_KEY]

You will get

{
 "kind": "youtube#videoListResponse",
 "etag": "*******",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#video",
   "etag": "*******",
   "id": "YVe2THgSDxc",
   "snippet": {
    "publishedAt": "2018-01-22T15:47:46.000Z",
    "channelId": "UCiP6wD_tYlYLYh3agzbByWQ",
    "title": "30 Minute HIIT Cardio*******",
    "description": "Full info for thi*******.",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/YVe2THgSDxc/default.jpg",
      "width": 120,
      "height": 90
     },
    *******
    },
    "channelTitle": "FitnessBlender",
    "tags": [
     "fitness blender",
     "fitness",
     "blender",
     "workout",
     "workout videos",
     "hiit workout",
     "cardio workout",
     "hiit cardio",
     "cardio at home",
     "hiit at home",
     "at home hiit",
     "at home workouts",
     "free workout videos",
     "hiit cardio workout",
     "strength",
     "strength training",
     "strength training workout",
     "dumbbell workout",
     "at home strength training",
     "strength and hiit",
     "hiit and strength",
     "lower body workout",
     "butt workout",
     "thigh workout",
     "butt and thigh workout",
     "fat burning workout",
     "muscle building workout"
    ],
    "categoryId": "26",
    "liveBroadcastContent": "none",
    "localized": {
     "title": "30 Minute HIIT Ca*******",
     "description": "Full info for this *******"
    }
   }
  }
 ]
}

So if you have users's channelID or channelName you can compare it with video's channelID or channelName.


If you have user's name but haven't his channel list you can get it by v3/channels

For example this gets channel list for user "popsugartvfit"

https://www.googleapis.com/youtube/v3/channels?&part=contentDetails&forUsername=popsugartvfit&key=[YOUR_API_KEY]

You will get

{
 "kind": "youtube#channelListResponse",
 "etag": "*****",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 5
 },
 "items": [
  {
   "kind": "youtube#channel",
   "etag": "*******",
   "id": "UCBINFWq52ShSgUFEoynfSwg",
   "contentDetails": {
    "relatedPlaylists": {
     "uploads": "UUBINFWq52ShSgUFEoynfSwg",
     "watchHistory": "HL",
     "watchLater": "WL"
    }
   }
  }
 ]
}

And use if for validation

like image 153
ABelikov Avatar answered Oct 05 '22 06:10

ABelikov