Java Google Youtube数据API::未经授权

Java Google Youtube数据API::未经授权,java,youtube-api,google-data-api,Java,Youtube Api,Google Data Api,我想用JavaGoogleDataAPI在youtube上上传一段视频。我从GoogleDataAPI文档中获得了以下代码来上传视频。我唯一需要更改的是在客户端ID和端口密钥中的代码。我正在使用followinf方法进行身份验证 YouTube服务=新的YouTube服务(客户端ID,开发者密钥) 客户端密钥是我的Google电子邮件id,使用wasy进行了尝试 仅提供用户名,例如。“采样用户” 或完整的Gmail id,例如。“sampleuser@gmail.com“或”smapleuse

我想用JavaGoogleDataAPI在youtube上上传一段视频。我从GoogleDataAPI文档中获得了以下代码来上传视频。我唯一需要更改的是在客户端ID和端口密钥中的代码。我正在使用followinf方法进行身份验证

YouTube服务=新的YouTube服务(客户端ID,开发者密钥)

客户端密钥是我的Google电子邮件id,使用wasy进行了尝试

  • 仅提供用户名,例如。“采样用户”
  • 或完整的Gmail id,例如。“sampleuser@gmail.com“或”smapleuser@googlemail.com"
如前所述,我通过记录我的Google mail id获得了开发者密钥”smapleuser@googlemail.com"

但我总是有以下例外

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("sampleuser@gmail.com",
            "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();
    }
}
请帮助,无法找到解决方案。非常感谢..正在寻找响应

尝试添加

service.setUserCredentials(“此处为电子邮件”、“此处为密码”)