YouTube API V3 - 为新提要获取推荐视频

Posted

技术标签:

【中文标题】YouTube API V3 - 为新提要获取推荐视频【英文标题】:YouTube API V3 - Get recommended video for new feed 【发布时间】:2017-08-20 06:07:34 【问题描述】:

作为关于实现和迁移到 API V3 的 YouTube 官方文档,他们说:

YouTube 数据 API (v2) 功能:Retrieve video recommendations v3 API 不会检索仅包含为当前 API 用户推荐的视频的列表。但是,您可以通过调用 activities.list 方法并将 home 参数值设置为 true 来使用 v3 API 查找推荐视频。

但现在参数home 也已被弃用。 目前,当我将home参数设置为true时,我只检索频道中最近上传的视频:Popular video in YouTube。根本没有snippet.type=recommendation 的视频。

我需要在新供稿中显示经过身份验证的用户的推荐视频,但 YouTube 似乎完全弃用了此功能。 有人有解决办法吗? 先谢谢了!

【问题讨论】:

【参考方案1】:

很遗憾,我找不到有关此功能的任何文档或示例。似乎这已被弃用。但是,您可以使用显示活动资源格式的示例 JSON 结构检查此 documentation,例如 recommendation:

"recommendation": 
      "resourceId": 
        "kind": string,
        "videoId": string,
        "channelId": string,
,

希望这会有所帮助!

【讨论】:

【参考方案2】:

该 api 的文档包括一种测试请求的方法。那里的代码示例展示了如何为经过身份验证的请求设置“我的”。

youtube activities

这是安卓示例代码。它需要在某个后台线程中。 channelList 响应上的 setmine = true 就像家一样(我认为)。不确定您的实现是针对网络还是应用程序。

这是安卓代码:

 YouTube youtube = new YouTube.Builder(transport, jsonFactory,
                    credential).setApplicationName(getString(R.string.app_name))
                    .build();

            YouTube.Activities.List activities;
            ActivityListResponse activityListResponse = null;
            List<ActivityData> activitiesData = new ArrayList<ActivityData>();

            try 
                /*
                 * Now that the user is authenticated, the app makes a
                 * channels list request to get the authenticated user's
                 * channel. Returned with that data is the playlist id for
                 * the uploaded videos.
                 * https://developers.google.com/youtube
                 * /v3/docs/channels/list
                 */

                ChannelListResponse clr = youtube.channels().list("contentDetails")
                        .setMine(true).execute();


               activities  = youtube.activities().list("id,snippet,subscriberSnippet");
                activities.setChannelId(clr.getItems().get(0).getId());

                activities.setMaxResults((long) 50);
                activityListResponse = activities.execute();

                ArrayList<String> subscriptionListIdentifier = new ArrayList<String>()
                        ,listTitles = new ArrayList<String>()
                        ,listThumbnails = new ArrayList<String>();

                List<Activity> results = activityListResponse.getItems();

                for (Activity activity : results) 
                    listTitles.add(activity.getSnippet().getTitle());
                    listThumbnails.add(activity.getSnippet().getThumbnails().getDefault().getUrl());
                    subscriptionListIdentifier.add(activity.getId());
                    //if ("public".equals(playlist.getStatus()
                    //        .getPrivacyStatus())) 
                    ActivityData data = new ActivityData();
                    data.setActivity(activity);
                    activitiesData.add(data);
                    //
                

                return activitiesData;

【讨论】:

【参考方案3】:

您可以使用以下 API 调用检索它们:

GET https://www.googleapis.com/youtube/v3/activitiespart=snippet%2CcontentDetails&channelId=channel—_Id&maxResults=25&regionCode=tw&key=YOUR_API_KEY

【讨论】:

【参考方案4】:

我发现了这个youtubes search api。我们需要做的就是在relatedToVideoId 中添加一个视频ID,它会给出一个与之相关的视频列表。

【讨论】:

以上是关于YouTube API V3 - 为新提要获取推荐视频的主要内容,如果未能解决你的问题,请参考以下文章