Question

try to get the favorite videos list from youtube but always get the

java.io.FileNotFoundException

below is my code

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 ;
}

and logcat is :

 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)

can anybody answer me why this exception occur???

thanks for any help

Was it helpful?

Solution

After lots of googling and try, i done this work with the help of client library and this is work for me.... https://developers.google.com/youtube/2.0/developers_guide_java#Retrieving_Favorite_Videos

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top