从YouTube获取用户的所有播放列表

时间:2017-10-27 07:45:20

标签: android youtube

我正在开发一个Android应用程序,用户将使用他们的Gmail帐户登录应用程序。我需要显示该用户的youtube播放列表列表。我使用了以下代码 -

 private String getAllPlayList() {
        YouTube youtube = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), new HttpRequestInitializer() {
            public void initialize(HttpRequest request) throws IOException {
            }
        }).setApplicationName("My Project").build();
        try {
            HashMap<String, String> parameters = new HashMap<>();
            parameters.put("part", "snippet,contentDetails");
            parameters.put("mine", "true");
            parameters.put("maxResults", "25");
            parameters.put("onBehalfOfContentOwner", "");
            parameters.put("onBehalfOfContentOwnerChannel", "");
            parameters.put("key","AIzaSyASISGgWoBqDijVmzUpYCbgaWJ_ULJWdiQ");

            YouTube.Playlists.List playlistsListMineRequest = youtube.playlists().list(parameters.get("part").toString());
            if (parameters.containsKey("mine") && parameters.get("mine") != "") {
                boolean mine = (parameters.get("mine") == "true") ? true : false;
                playlistsListMineRequest.setMine(true);
            }

            if (parameters.containsKey("maxResults")) {
                playlistsListMineRequest.setMaxResults(Long.parseLong(parameters.get("maxResults").toString()));
            }

            if (parameters.containsKey("onBehalfOfContentOwner") && parameters.get("onBehalfOfContentOwner") != "") {
                playlistsListMineRequest.setOnBehalfOfContentOwner(parameters.get("onBehalfOfContentOwner").toString());
            }

            if (parameters.containsKey("onBehalfOfContentOwnerChannel") && parameters.get("onBehalfOfContentOwnerChannel") != "") {
                playlistsListMineRequest.setOnBehalfOfContentOwnerChannel(parameters.get("onBehalfOfContentOwnerChannel").toString());
            }
            if (parameters.containsKey("key") && parameters.get("key") != "") {
                playlistsListMineRequest.setKey(parameters.get("key").toString());
            }
            PlaylistListResponse response = playlistsListMineRequest.execute();
            Log.d("PlayList",response.toString());
            return response.toPrettyString();
        }
        catch (Exception e)
        {
            e.printStackTrace();
            return e.getMessage().toString();
        }

    }

但我得到了以下回复 -

“message”:“请求使用mine参数,但未经过适当授权。”,

请帮忙。

0 个答案:

没有答案