3

有没有办法通过 YouTube 合作伙伴 API 获取特定视频的内容所有者信息(归属)?

例如,此视频:http ://www.youtube.com/watch?v=I67cgXr6L6o&feature=c4-overview&list= UUGnjeahCJW1AF34HBmQTJ-Q 归属于 VEVO。

有没有办法通过 API 以某种方式获取该信息?

4

3 回答 3

2

现在有可能:

https://developers.google.com/youtube/partner/docs/v1/ownership/

[编辑]

我已经使用此示例 创建了下面的片段并成功获得了资产内容所有者。您将需要正确设置您的 python 环境和 clients_secrets.file

#!/usr/bin/python

import httplib2
import os
import sys
import logging
import requests
import json
import time

from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import flow_from_clientsecrets
from oauth2client.tools import argparser, run_flow
from symbol import for_stmt







# The CLIENT_SECRETS_FILE variable specifies the name of a file that contains
# the OAuth 2.0 information for this application, including its client_id and
# client_secret. You can acquire an OAuth 2.0 client ID and client secret from
# the Google Developers Console at
# https://console.developers.google.com/.
# Please ensure that you have enabled the YouTube Data API for your project.
# For more information about using OAuth2 to access the YouTube Data API, see:
#   https://developers.google.com/youtube/v3/guides/authentication
# For more information about the client_secrets.json file format, see:
#   https://developers.google.com/api-client-library/python/guide/aaa_client_secrets
CLIENT_SECRETS_FILE = "client_secrets.json"

# This variable defines a message to display if the CLIENT_SECRETS_FILE is
# missing.
MISSING_CLIENT_SECRETS_MESSAGE = """
WARNING: Please configure OAuth 2.0

To make this sample run you will need to populate the client_secrets.json file
found at:

   %s

with information from the Developers Console
https://console.developers.google.com/

For more information about the client_secrets.json file format, please visit:
https://developers.google.com/api-client-library/python/guide/aaa_client_secrets
""" % os.path.abspath(os.path.join(os.path.dirname(__file__), CLIENT_SECRETS_FILE))

YOUTUBE_SCOPES = (
  # This OAuth 2.0 access scope allows for read-only access to the authenticated
  # user's account, but not other types of account access.
  "https://www.googleapis.com/auth/youtube.readonly",
  # This OAuth 2.0 scope grants access to YouTube Content ID API functionality.
  "https://www.googleapis.com/auth/youtubepartner")
YOUTUBE_API_SERVICE_NAME = "youtube"
YOUTUBE_API_VERSION = "v3"
YOUTUBE_PARTNER_API_SERVICE_NAME = "youtubePartner"
YOUTUBE_PARTNER_API_VERSION = "v1"

KEY = "USE YOUR KEY"


# Authorize the request and store authorization credentials.
def get_authenticated_services(args):
  flow = flow_from_clientsecrets(CLIENT_SECRETS_FILE, scope=" ".join(YOUTUBE_SCOPES), message=MISSING_CLIENT_SECRETS_MESSAGE)

  storage = Storage("%s-oauth2.json" % sys.argv[0])
  credentials = storage.get()

  if credentials is None or credentials.invalid:
    credentials = run_flow(flow, storage, args)

  youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION,  http=credentials.authorize(httplib2.Http()))

  youtube_partner = build(YOUTUBE_PARTNER_API_SERVICE_NAME, YOUTUBE_PARTNER_API_VERSION, http=credentials.authorize(httplib2.Http()))

  return (youtube, youtube_partner)


def get_content_owner_id(youtube_partner):
  content_owners_list_response = youtube_partner.contentOwners().list(fetchMine=True).execute()

  return content_owners_list_response["items"][0]["id"]
#def

def claim_search(youtube_partner, content_owner_id, _videoId):

  video_info = get_video_info(_videoId)  
  print '\n---------- CLAIM SEARCH LIST - VIDEO (',video_info['title'],') ID: (',_videoId,')'
  claims = youtube_partner.claimSearch().list( videoId=_videoId, onBehalfOfContentOwner=content_owner_id).execute()
  print ' --- CLAIMS: ',claims

  if claims['pageInfo']['totalResults'] < 1:
    print " --- DOESN'T HAVE CLAIMS"
    return

  assetId = claims['items'][0]['assetId']
  print ' --- ASSET ID: ', assetId

  ownershipHistory = youtube_partner.ownershipHistory().list(assetId=assetId, onBehalfOfContentOwner=content_owner_id).execute()
  print ' --- OWNERSHIP HISTORY: ', ownershipHistory  

  contentOwnerId = ownershipHistory['items'][0]['origination']['owner']
  print ' --- CONTENT OWNER ID: ', contentOwnerId

  contentOwners = youtube_partner.contentOwners().get(contentOwnerId=contentOwnerId, onBehalfOfContentOwner=content_owner_id).execute()
  print ' --- CONTENT OWNERS: ', contentOwners


def get_video_info(videoId):
  r = requests.get("https://www.googleapis.com/youtube/v3/videos?id="+videoId+"&part=id,snippet,contentDetails,status,statistics,topicDetails,recordingDetails&key="+KEY)
  content = r.content

  content = json.loads(content)
  return content['items'][0]['snippet']






if __name__ == "__main__":
  args = argparser.parse_args()
  (youtube, youtube_partner) = get_authenticated_services(args)

  #video id's. Ex: "https://www.youtube.com/watch?v=lgSLz5FeXUg"
  videos = ['I67cgXr6L6o', 'lgSLz5FeXUg']

  content_owner_id = get_content_owner_id(youtube_partner)

  for vid in videos :
      claim_search(youtube_partner, content_owner_id, vid)
      time.sleep(0.5)

(审查)证明: 在此处输入图像描述

于 2016-02-04T15:00:47.377 回答
0

无法检查其他人对视频或频道的所有权或管理权。YouTube 故意避免这种情况。

于 2013-10-03T14:10:43.640 回答
0

虽然ownershipHistory有效,但我看到使用选项GET https://www.googleapis.com/youtube/partner/v1/assets?id=[multiple asset ids]调用它时也有效fetchOwnership=effective

https://developers.google.com/youtube/partner/docs/v1/assets/list

于 2019-04-22T18:14:44.013 回答