0

尝试从 youtube 获取最喜欢的视频列表,但始终获取

java.io.FileNotFoundException

下面是我的代码

String qurl = "https://gdata.youtube.com/feeds/api/users/default/favorites?alt=json&v=2&access_token=xxxxxxxxxxxx" ;

DownloadTask task = new DownloadTask();
task.execute(qurl);




public class DownloadTask extends AsyncTask<String , Void, Void>
{

        @Override
        protected Void doInBackground(String... url) {
            String playlistFetchUrl = url[0];
            try {
                String data = downloadUrl(playlistFetchUrl);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
    }

}


private String downloadUrl(String StrUrl) throws IOException{
    HttpURLConnection urlConnection = null;
    InputStream isStream = null ;
    String data = "";
    try {
        URL url = new URL(StrUrl);

        // Creating an http connection to communicate with url 
        urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setRequestMethod("GET");
        urlConnection.connect();
        isStream = urlConnection.getInputStream();

        BufferedReader br = new BufferedReader(new InputStreamReader(isStream));

        StringBuffer sb  = new StringBuffer();

        String line = "";
        while( ( line = br.readLine())  != null){
            sb.append(line);
        }

        data = sb.toString();

        br.close();

    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    catch(IOException e){
        e.printStackTrace();
    }
    catch(Exception e){
        e.printStackTrace();
    }
    finally{
        isStream.close();
        urlConnection.disconnect();
    }
    return data ;
}

和 logcat 是:

 W/System.err(15212): java.io.FileNotFoundException: https://gdata.youtube.com/feeds/api/users/default/favorites?alt=json&v=2&access_token=xxxxxxxxxxxxxxxxxxxxx

 W/System.err(15212):   at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:186)

W/System.err(15212):    at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:246)

谁能回答我为什么会发生这种异常???

谢谢你的帮助

4

1 回答 1

0

经过大量的谷歌搜索和尝试,我在客户端库的帮助下完成了这项工作,这对我来说是工作...... https://developers.google.com/youtube/2.0/developers_guide_java#Retrieving_Favorite_Videos

于 2013-12-05T17:56:59.587 回答