Google/Youtube Api(第3版) - 验证视频的所有者

Igo*_*gna 6 php youtube-api symfony

上下文:
我正在使用Symfony2(php)构建一个网站,我已经实现了一个社交(谷歌)登录功能(通过HWIOAuthBundle),允许用户:
- 使用自己的谷歌帐户注册一个新帐户
- 链接谷歌帐户现有的非社交帐户
因此,在我的数据库中,该users表已有一个google_id字段.

我想做什么:
用户必须能够提交自己视频的YouTube链接.这些链接将保存在数据库中但首先我需要验证提交链接的用户的视频BELONGS(已拥有).换句话说:用户无法提交其他人上传的视频.
我打算使用你可以在谷歌开发者网站上找到的Youtube API(php).

问题:
我如何验证这种情况?我可以使用users桌面上已有的Google ID 吗?或者我是否需要创建一个新youtube_id字段,因为id不同于google_id?我应该调用什么api功能/方法来验证视频所有权?
想法?

ABe*_*kov 1

尝试通过 v3/videos 检查它们 - https://developers.google.com/youtube/v3/docs/videos/list

如果您使用“part=snippet”,您将在 items->snippet->channelId 和 items->snippet->channelTitle 中看到频道信息

例如对于https://www.youtube.com/watch?v=YVe2THgSDxc负载

https://www.googleapis.com/youtube/v3/videos?id=YVe2THgSDxc&part=snippet&key=[YOUR_API_KEY]
Run Code Online (Sandbox Code Playgroud)

你会得到

{
 "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 *******"
    }
   }
  }
 ]
}
Run Code Online (Sandbox Code Playgroud)

因此,如果您有用户的channelID或channelName,您可以将其与视频的channelID或channelName进行比较。


如果您有用户名但没有他的频道列表,您可以通过 v3/channels 获取它

例如,这获取用户“popsugartvfit”的频道列表

https://www.googleapis.com/youtube/v3/channels?&part=contentDetails&forUsername=popsugartvfit&key=[YOUR_API_KEY]
Run Code Online (Sandbox Code Playgroud)

你会得到

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

并使用 if 进行验证