如何使用Youtube API v3获取自动生成频道的本地化标题和说明?

时间:2014-10-01 03:51:51

标签: youtube internationalization youtube-api

我有一个使用v3 YouTube API的应用程序,可以通过指南API浏览视频,从指南类别向下钻取到频道到视频。

我想提供本地化的结果,但在我希望本地描述的地方获取英文文本。我意识到我不能期望属于用户的频道被本地化,但是一些结果似乎是自动生成的频道,这些频道将在网络上翻译。

我可以轻松获取指南类别列表,例如:西班牙人致电youtube.guideCategories.list(part=snippet, hl=es-ES, regionCode=ES)

{
  "kind": "youtube#guideCategoryListResponse",
  "etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/RxpLDjICTxI6pEJgKxa1GihOABg\"",
  "items": [
    {
      "kind": "youtube#guideCategory",
      "etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/fnL4T7wf3HKS8VCeb2Mui5q9zeM\"",
      "id": "GCQmVzdCBvZiBZb3VUdWJl",
      "snippet": {
        "channelId": "UCBR8-60-B28hp2BmDPdntcQ",
        "title": "Best of YouTube"
      }
    },
    ...
    {
      "kind": "youtube#guideCategory",
      "etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/a2ukJS2cvl7NN20p8C2B9uYePoM\"",
      "id": "GCTXVzaWM",
      "snippet": {
        "channelId": "UCBR8-60-B28hp2BmDPdntcQ",
        "title": "Música"
      }
    },
    ...
  }
}

除了像#34; Best of YouTube"这样的一些结果之外,它还会返回我期望的本地化指南类别标题。当我想深入研究其中一个类别时,就会出现问题。

例如,如果我想在" Best of YouTube"类别,我打电话给youtube.channels.list(part=snippet, categoryId=GCQmVzdCBvZiBZb3VUdWJl)

{
  "kind": "youtube#channelListResponse",
  "etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/o8HbT_CvdwGx45Gqb3VT3jnxz8Y\"",
  "nextPageToken": "CAUQAA",
  "pageInfo": {
    "totalResults": 9,
    "resultsPerPage": 5
  },
  "items": [
    {
      "kind": "youtube#channel",
      "etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/3COvNpjUozOrHwTDRG2SKLHlbDs\"",
      "id": "UCEgdi0XIXXZ-qJOFPf4JSKw",
      "snippet": {
        "title": "Sports",
        "description": "Sport is all forms of usually competitive physical activity which, ....\nThis channel was generated automatically by YouTube's video discovery system.",
        "publishedAt": "2013-12-15T20:39:04.000Z",
        "thumbnails": {
          "default": {
            "url": "https://i.ytimg.com/i/Egdi0XIXXZ-qJOFPf4JSKw/1.jpg"
          },
          "medium": {
            "url": "https://i.ytimg.com/i/Egdi0XIXXZ-qJOFPf4JSKw/mq1.jpg"
          },
          "high": {
            "url": "https://i.ytimg.com/i/Egdi0XIXXZ-qJOFPf4JSKw/hq1.jpg"
          }
        }
      }
    },
    ...
  }
}

正如您所看到的,这个自动生成的频道会返回英文标题和说明。没有记录此API以使用hl参数来设置所需的语言,并且如果我使用该参数调用它,则不会有任何不同的行为。我也尝试过设置Accept-Language HTTP请求标头而没有任何运气。

如果我在YouTube网站上https://www.youtube.com/channel/UCEgdi0XIXXZ-qJOFPf4JSKw浏览此特定自动生成的频道,并将网站语言更改为西班牙语,我会看到本地化标题" Deportes"和相应的描述,有没有办法通过API获得相同的信息?

2 个答案:

答案 0 :(得分:1)

Data API v3中的国际化是YT最近开始支持的,现在它受到限制。但是有一项工作正在进行,以便尽快为API中的所有功能提供支持。

答案 1 :(得分:0)

自我发布问题以来,YouTube channels.list调用看起来已获得hl参数,因此可以检索本地化结果。

例如,我可以通过调用youtube.channels.list(part=snippet, categoryId=GCQmVzdCBvZiBZb3VUdWJl, hl=es-ES)来检索“Best of YouTube”类别的西班牙语本地化版本:

{
 "kind": "youtube#channelListResponse",
 "etag": "\"0KG1mRN7bm3nResDPKHQZpg5-do/5ZMIP3f0vZw8CYq69TcuOdye2ZQ\"",
 "nextPageToken": "CAUQAA",
 "pageInfo": {
  "totalResults": 10,
  "resultsPerPage": 5
 },
 "items": [
  ...
  {
   "kind": "youtube#channel",
   "etag": "\"0KG1mRN7bm3nResDPKHQZpg5-do/kLIkkfyIIZLFzhOb7gB4CIPzKJQ\"",
   "id": "UCEgdi0XIXXZ-qJOFPf4JSKw",
   "snippet": {
    "title": "#Sports",
    "description": "Sport or sports are all forms of usually competitive physical activity which, through casual or organised participation, aim to use, maintain or improve physical ability and skills while providing entertainment to participants, and in some cases, spectators. Usually the contest or game is between two sides, each attempting to exceed the other. Some sports allow a tie game; others provide tie-breaking methods, to ensure one winner and one loser. A number of such two-sided contests may be arranged in a tournament producing a champion. Many sports leagues make an annual champion by arranging games in a regular sports season, followed in some cases by playoffs. Hundreds of sports exist, from those between single contestants, through to those with hundreds of simultaneous participants, either in teams or competing as individuals. In certain sports such as racing, many contestants may compete, each against all w...\nThis channel was generated automatically by YouTube's video discovery system.",
    "publishedAt": "2013-12-15T20:39:04.000Z",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/i/Egdi0XIXXZ-qJOFPf4JSKw/1.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/i/Egdi0XIXXZ-qJOFPf4JSKw/mq1.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/i/Egdi0XIXXZ-qJOFPf4JSKw/hq1.jpg"
     }
    },
    "localized": {
     "title": "#Deportes",
     "description": "El deporte es una actividad física reglamentada, normalmente de carácter competitivo, que puede mejorar la condición física y ocasionalmente psíquica de quien lo practica, y tiene propiedades que lo diferencian del juego.\nLa RAE, en su Diccionario de la lengua española, define deporte como una «actividad física, ejercida como juego o competición, cuya práctica supone entrenamiento y sujeción a normas»; también, en una segunda acepción, más amplia, como «recreación, pasatiempo, placer, diversión o ejercicio físico, por lo común al aire libre». Por otra parte, la Carta Europea del deporte lo define como: «Todas las formas de actividades físicas que mediante una participación organizada o no, tienen como objetivo la expresión o la mejora de la condición física y psíquica, el desarrollo de las relaciones sociales o la obtención de resultados en competición de todos los niveles».\nInstitucionalmente, para...\nEl sistema de detección de vídeos de YouTube ha generado este canal automáticamente."
    }
   }
  },
  ...
 }
}

本地化标题和说明显示在渠道对象的新localized属性下。