1
獲取YouTube頻道洞察信息我正在使用以下代碼獲取我的頻道洞察數據的鏈接。 莫名其妙地我的代碼作爲鏈接返回null。通過API
/* 代碼* **/
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. [email protected]
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") + ":");
/* ** * ****END* ** * ** * ***/
我像鏈接入門零這裏
誰能幫助我在這裏找到了什麼問題嗎?
謝謝, 邁克
嗨,感謝您關注此問題, 我已經通過UI登錄訪問提要,並且開發人員密鑰是正確的。 這裏是我的結果標準輸出: System.out.println(channelFeed.getEntries()+「:」); [[email protected],[email protected],.... etc] System.out.println(「Link:」+ channelFeed .getLink(「http://gdata.youtube.com/schemas/2007#insight.views」,「text/html」)+「:」); 鏈接:null: System.out.println(channelFeed); [email protected] 可以驗證代碼中使用的'FEED_URL'是否確切嗎? -Mike – MikA 2012-01-16 13:52:31
我不確定哪個URL要用於FEED_URL,但是您是否使用'https:// gdata.youtube.com/feeds/api/users/default'和'https: // gdata.youtube.com/feeds/api/users/username'(用你的用戶名替換第二個用戶名)。這可能是洞察信息是通過用戶配置文件信息發送的,而不是通道信息,這就是您現在請求的內容。 – aoi222 2012-01-16 14:52:39
我已更改代碼如下: YouTubeService服務=新YouTubeService(clienID,developerKey); query = new Query(new URL(「https://gdata.youtube.com/feeds/api/users/username」)); profileFeed = service.query(query,ProfileFeed.class); System.out.println(profileFeed.getEntries()+「:」); System.out.println(「Link:」+ profileFeed.getLink(「http://gdata.youtube.com/schemas/2007#insight.views」,「text/html」)+「:」); System.out。的println(profileFeed); 但我仍然收到錯誤.. :( -Mike – MikA 2012-01-16 16:11:24