Java 通过API检索YouTube频道洞察
我正在使用下面的代码获取我的Channel insight数据的链接。 不知何故,我的代码返回null作为链接 /*代码***/Java 通过API检索YouTube频道洞察,java,youtube-api,gdata-api,youtube-channels,Java,Youtube Api,Gdata Api,Youtube Channels,我正在使用下面的代码获取我的Channel insight数据的链接。 不知何故,我的代码返回null作为链接 /*代码***/ public static final String FEED_URL = "http://gdata.youtube.com/feeds/api/users/mychannelname/uploads"; //i put my channel's name in 'mychannelname' String username = "mygmailid";
public static final String FEED_URL = "http://gdata.youtube.com/feeds/api/users/mychannelname/uploads"; //i put my channel's name in 'mychannelname'
String username = "mygmailid"; //here i entered my gmail id eg. mikeme@gmail.com
String password = "mypassword";
String developerKey = "AI39si7ffVeKWbG1k37***********************************************" //developer key
YouTubeService service = new YouTubeService( username ,developerKey); //just put username instead of clientid since client id no longer available
try {
service.setUserCredentials(username, password);
} catch (AuthenticationException e) {
System.out.println("Invalid login credentials.");
System.exit(1);
}
Query query = null;
try {
query = new Query(new URL( FEED_URL));
} catch (MalformedURLException e) {
//TODO Auto-generated catch block
e.printStackTrace();
}
ChannelFeed channelFeed = null;
try {
channelFeed = service.query(query, ChannelFeed.class);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(channelFeed.getEntries() + ":");
System.out.println(" Link : "+channelFeed.getLink("http://gdata.youtube.com/schemas/2007#insight.views", "text/html") + ":");
/*********结束************/
public static final String FEED_URL = "http://gdata.youtube.com/feeds/api/users/mychannelname/uploads"; //i put my channel's name in 'mychannelname'
String username = "mygmailid"; //here i entered my gmail id eg. mikeme@gmail.com
String password = "mypassword";
String developerKey = "AI39si7ffVeKWbG1k37***********************************************" //developer key
YouTubeService service = new YouTubeService( username ,developerKey); //just put username instead of clientid since client id no longer available
try {
service.setUserCredentials(username, password);
} catch (AuthenticationException e) {
System.out.println("Invalid login credentials.");
System.exit(1);
}
Query query = null;
try {
query = new Query(new URL( FEED_URL));
} catch (MalformedURLException e) {
//TODO Auto-generated catch block
e.printStackTrace();
}
ChannelFeed channelFeed = null;
try {
channelFeed = service.query(query, ChannelFeed.class);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(channelFeed.getEntries() + ":");
System.out.println(" Link : "+channelFeed.getLink("http://gdata.youtube.com/schemas/2007#insight.views", "text/html") + ":");
我这里的链接为空
有人能帮我找出这里出了什么问题吗
谢谢,
Mike它很可能返回null,因为它找不到与您提供的相对名称对应的链接。由于channel Insight信息仅适用于与您通过身份验证的用户对应的频道,因此可能是因为它未授权您的用户查看该频道Insight数据,这可能是因为您的google帐户未与youtube帐户链接
我会尝试打印您得到的回复,以确保您得到了您认为得到的所有数据。您好,感谢您调查这个问题,我可以通过UI登录访问提要,并且开发密钥是正确的。以下是我的结果的标准输出:System.out.println(channelFeed.getEntries()+“:”);[com.google.gdata.data.youtube。ChannelEntry@413ffc,com.google.gdata.data.youtube。ChannelEntry@1cfc2c0,etc]System.out.println(“链接:“+channelFeed.getLink”(“,“text/html”)+”:”;Link:null:System.out.println(channelFeed);com.google.gdata.data.youtube。ChannelFeed@1239010你能验证代码中使用的“FEED_URL”是准确的吗-MikeI不知道你想用哪个URL作为FEED\u URL,但是你用
https://gdata.youtube.com/feeds/api/users/default
和https://gdata.youtube.com/feeds/api/users/username
(将第二个中的“用户名”替换为您的用户名)。可能是insight信息与用户配置文件信息一起发送,而不是频道信息,这是您现在请求的信息;query=newquery(newurl(“);profileFeed=service.query(query,profileFeed.class);System.out.println(profileFeed.getEntries()+”:”);System.out.println(“Link:“+profileFeed.getLink(”,“text/html”)+”:”;System.out.println(profileFeed);但我仍然得到错误:(-Mike)