【问题标题】:android youtube data api安卓 youtube 数据 api
【发布时间】:2018-05-07 15:26:32
【问题描述】:

我正在尝试通过其 ID 查找 youtube 视频的详细信息(示例 -> yb7E4lQiaZI)。我读到,如果我们只需要详细信息,我们可以使用开发人员控制台中的 api_key。如果我们要进行上传视频等操作,我们需要使用 oauth。我只想和第一个案例一起去。我只需要视频的详细信息,例如我想在列表视图中显示的缩略图 url 和标题。

我正在尝试使用我的 api_key 来执行此操作,但我无法使其工作。最后一行 (system.out.println) 没有打印任何内容。我写的代码如下

    try {

        YouTube youtube = new YouTube.Builder(HTTP_TRANSPORT, JSON_FACTORY, new 
        HttpRequestInitializer() {
            public void initialize(HttpRequest request) throws IOException {
            }
        }).setApplicationName("my_project").build();

        HashMap<String, String> parameters = new HashMap<>();
        parameters.put("part", "snippet,contentDetails,statistics");
        parameters.put("id", "yb7E4lQIaZI");

        YouTube.Videos.List videosListByIdRequest = youtube.videos().list(parameters.get("part").toString());
        videosListByIdRequest.setKey(MY_API_KEY_FROM_DEVELOPER_CONSOLE);
        if (parameters.containsKey("id") && parameters.get("id") != "") {
            videosListByIdRequest.setId(parameters.get("id").toString());
        }

        VideoListResponse response = videosListByIdRequest.execute();
        System.out.println(response);


    } catch (GoogleJsonResponseException e) {
        e.printStackTrace();
        System.err.println("There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage());
    } catch (Throwable t) {
        t.printStackTrace();
    }

当我运行调试时,它在“VideoListResponse response = videosListByIdRequest.execute();”行之后退出并且不会转到“System.out.println(response)”行。

应用程序不会崩溃或显示任何错误,它只是不会进入 'system.out.print' 行

【问题讨论】:

    标签: android api youtube


    【解决方案1】:

    您是否检查过您是否在清单中添加了互联网权限。

    <uses-permission android:name="android.permission.INTERNET" />
    

    【讨论】:

    • 是的..我已经添加了..我可以运行视频但无法让 youtube 数据 api 工作
    猜你喜欢
    • 2018-01-16
    • 2017-08-02
    • 2016-08-28
    • 2011-11-24
    • 2013-05-10
    • 2012-02-25
    • 1970-01-01
    • 2015-10-14
    • 2014-10-18
    相关资源
    最近更新 更多