我最近了解到谷歌提供的YouTube API。我正在创建一个Android应用程序,允许其用户通过应用程序观看YouTube上的视频(或视频)。
到目前为止,在This在线教程的帮助下;我已将网络服务集成到应用中,我正在尝试从特定的YouTube帐户/频道获取视频上传列表。它到目前为止工作正常,但每当我启动应用程序并单击按钮从YouTube获取数据时,它将返回一个空列表。
以下是与YouTube公开API互动的课程。我已经有其他课程来帮助实现这个目标,但看到我有一个空列表返回,我猜我可能在这里错过/出错...或者可能没有。
private static final String YouTubeVideoUrl =
"https://gdata.youtube.com/feeds/api/users/Patrick%20Tolani/uploads?v=2&alt=jsonc";
private static final String logTag = "OpenHeavenReflection";
private static byte[] buff = new byte[1024];
private static final int http_is_ok = 200;
public static class ApiException extends Exception{
private static final long serialVersionUID = 1L;
public ApiException(String msg){
super (msg);
}
public ApiException(String msg, Throwable thr){
super(msg, thr);
}
}
/*
* Download most recent uploads from a particular YouTube account user
* @params
* @return An array of json strings returned by the YouTube API
* @throws ApiException
*/
protected static synchronized String getVideosFromServer(String... params) throws ApiException{
String url = YouTubeVideoUrl;
String returnVal = null;
Log.d(logTag,"Fetching " + url);
//Here I'll now create a HTTP client and a request object.
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet();
try {
//Here I'll execute the request
HttpResponse response = client.execute(request);
StatusLine status = response.getStatusLine();
if(status.getStatusCode() != http_is_ok){
throw new ApiException("Invalid response from YouTube" +
status.toString());
}
//Here I'll process the content.
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
ByteArrayOutputStream content = new ByteArrayOutputStream();
int countRead = 0;
while((countRead = is.read(buff)) != -1){
content.write(buff, 0, countRead);
}
/*this returns a string of the recent uploads
* by the specified YouTube account.
*/
returnVal = new String(content.toByteArray());
}
catch(Exception e){
throw new ApiException("Problem connecting to Server" + e.getMessage(), e);
}
return returnVal;
}
你能帮我理解为什么会得到一个空列表吗?