Google/Youtube Api(v3)-验证视频的所有者



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

我想做的事:
用户必须能够提交自己视频的youtube链接。这些链接将保存在数据库中,但首先我需要验证视频是否属于提交链接的用户。换句话说:用户不能提交其他人上传的视频
我计划使用Youtube API(php),你可以在谷歌开发者网站上找到它。

问题:
如何验证这种情况?我可以使用users表中已有的Google Id吗?或者我需要创建一个新的youtube_id字段,因为id与google_id不同?我应该调用什么api函数/方法来验证视频所有权
想法?

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

如果使用"part=snippet"您将在项目->片段->channelId和项目->片段->频道标题中看到频道信息

例如https://www.youtube.com/watch?v=YVe2THgSDxc加载

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

你会得到

{
 "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 *******"
    }
   }
  }
 ]
}

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


如果你有用户名,但没有他的频道列表你可以通过v3/频道获得

例如,这将获得用户"popsugartvfit"的频道列表

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

你会得到

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

并使用if进行验证

相关内容

  • 没有找到相关文章

最新更新