Java YouTube上的Android流返回空值?
我最近了解到谷歌提供的YouTube API。我正在创建一个Android应用程序,允许其用户通过该应用程序在YouTube上观看视频 到目前为止,在在线教程的帮助下;我已将web服务集成到应用程序中,通过该应用程序,我试图获取从特定YouTube帐户/频道上传的视频列表。到目前为止,它工作正常,但每当我启动应用程序并单击按钮从YouTube获取数据时,它都会返回一个空列表 下面是与YouTube公共API交互的类。我已经加入了其他课程来帮助实现这个目标,但是看到我返回了一个空的列表,我猜我可能错过了这里的某个地方/出了问题……或者可能没有Java YouTube上的Android流返回空值?,java,android,youtube,youtube-api,video-streaming,Java,Android,Youtube,Youtube Api,Video Streaming,我最近了解到谷歌提供的YouTube API。我正在创建一个Android应用程序,允许其用户通过该应用程序在YouTube上观看视频 到目前为止,在在线教程的帮助下;我已将web服务集成到应用程序中,通过该应用程序,我试图获取从特定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;
}
你能帮我理解为什么我得到一个空列表吗?先试试这个语法:Intent-Intent=new-Intent(this,OpenHeaves.class);IDE应该要求您导入该类。这个字符串中可能有输入错误。@IkaiLan由于上面提供的教程,我对以前的解决方案进行了更改。但我一定会尝试你的建议,因为我仍然有老办法。