2011-11-21 121 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");