2012-01-14 54 views
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* ** * ** * ***/

我像鏈接入門零這裏

誰能幫助我在這裏找到了什麼問題嗎?

謝謝, 邁克

回答

0

這是最有可能返回null,因爲它無法找到與您提供的相關名稱的鏈接。由於渠道Insight信息僅適用於與您通過身份驗證的用戶對應的渠道,因此您可能無法授權用戶查看該渠道洞察數據,這可能是因爲您的Google帳戶未與您的YouTube相關聯帳戶。

我會嘗試打印出你回來的回覆,以確保你得到了所有你認爲你得到的數據。

+0

嗨,感謝您關注此問題, 我已經通過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

+0

我不確定哪個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

+0

我已更改代碼如下: 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