0
得到用戶的喜愛視頻列表

嘗試從YouTube獲得最喜愛的影片名單,但總是能得到嘗試從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 ; 
} 

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) 

任何人都可以回答我爲什麼會發生這種異常?

感謝您的幫助

回答