2011-11-21 81 views
-1

我想使用Java Google Data API在YouTube上上傳視頻。我從Google Data Api文檔中獲得以下鱈魚來上傳視頻。我需要在客戶端ID和Porduct密鑰的此代碼中更改唯一的內容。我正在使用followinf方法進行身份驗證Java Google Youtube Data API ::未授權

YouTubeService service = new YouTubeService(clientID,developer_key);

客戶關鍵是我的谷歌的電子郵件,與WASY試過,

我登錄我的谷歌的郵件編號提到「[email protected]

,但我總是得到以下異常了開發人員密鑰

com.google.gdata.util.AuthenticationException: Unauthorized 
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:600) 
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563) 
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552) 
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530) 
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535) 
at com.google.gdata.client.media.MediaService.insert(MediaService.java:400) 
at YouTube.videoUpload(YouTube.java:115) 
at YouTube.main(YouTube.java:43) 

這裏是我的視頻上傳

YouTubeService service = new YouTubeService("[email protected]", 
      "fakegoogleapplicationidjsuttoshowthatimgivingidhere"); 
    // YouTubeService service = new YouTubeService("My Application"); 
    VideoEntry newEntry = new VideoEntry(); 

    YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup(); 
    mg.setTitle(new MediaTitle()); 
    mg.getTitle().setPlainTextContent("My Test Movie"); 
    mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, "Autos")); 
    mg.setKeywords(new MediaKeywords()); 
    mg.getKeywords().addKeyword("cars"); 
    mg.getKeywords().addKeyword("funny"); 
    mg.setDescription(new MediaDescription()); 
    mg.getDescription().setPlainTextContent("My description"); 
    mg.setPrivate(false); 
    mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "mydevtag")); 
    mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "anotherdevtag")); 

    newEntry.setGeoCoordinates(new GeoRssWhere(37.0,-122.0)); 
    // alternatively, one could specify just a descriptive string 
    // newEntry.setLocation("Mountain View, CA"); 

    MediaFileSource ms = new MediaFileSource(new File("D:\\maths.mp4") 
    , "video/quicktime"); 
    newEntry.setMediaSource(ms); 

    // "http://uploads.gdata.youtube.com/feeds/api/users/default/uploads"; 
    String uploadUrl = 
     "http://uploads.gdata.youtube.com/feeds/api/users/default/uploads"; 

    try { 
     VideoEntry createdEntry = service.insert(new URL(uploadUrl), newEntry); 
    } catch (MalformedURLException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (ServiceException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
} 

請大家幫忙,無法找到解決方案代碼。謝謝你這麼much..looking爲響應

回答

0

嘗試添加

service.setUserCredentials("email_here", "password_here");