【问题标题】:I'm getting troubles while uploading to Youtube with google java client: "Invalid value for: listed is not a valid value"我在使用 google java 客户端上传到 Youtube 时遇到问题:“无效值:列出的值不是有效值”
【发布时间】:2013-10-05 11:56:02
【问题描述】:

我正在尝试使用 https://code.google.com/p/youtube-api-samples/source/browse/samples/java/youtube-cmdline-uploadvideo-sample/src/main/java/com/google/api/services/samples/youtube/cmdline/youtube_cmdline_uploadvideo_sample/UploadVideo.java 示例上传视频

我已经在 youtube 控制台成功注册,并在https://code.google.com/apis/console/?api=youtube#project:340964720118:access 获得了client_secrets.json

我已经安装了这些秘密,所以我的应用可以访问它们;一切都编译得很好,但是当程序执行时,我得到了那个奇怪的错误:

GoogleJsonResponseException code: 400 : Invalid value for: listed is not a valid value
com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
  "code" : 400,
  "errors" : [ {
    "domain" : "global",
    "message" : "Invalid value for: listed is not a valid value",
    "reason" : "invalid"
  } ],
  "message" : "Invalid value for: listed is not a valid value"
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:423)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)

我无法找出问题所在;由于请求本身被深度封装,所以我无法理解请求有什么问题......

更新。

感谢

 System.out.println(videoInsert.getHttpContent().toString());

调用插入到

之前
 Video returnedVideo = videoInsert.execute();

在示例代码中,我得到了 JSOn 形成并发送到谷歌是

{snippet={description=Video uploaded via YouTube Data API V3 using the Java library on Sun Sep 29 20:29:30 MSK 2013, tags=[test], title=Test Upload via Java on Sun Sep 29 20:29:30 MSK 2013}, status={privacyStatus=listed}}

但实际上仍然存在一个问题,这个 json 是什么以及为什么它会导致服务器端的错误。

UPD 2:

而且我不再收到上面的消息,但上传仍然是不可能的。尝试上传上述示例行中的文件时出现 401 错误:

        System.out.println(videoInsert.getJsonContent().toString());
        System.out.println(videoInsert.getHttpContent().getType());
        Video returnedVideo = videoInsert.execute();
        System.out.println(returnedVideo.getId());

我认为我没有授权对我的个人数据的请求,但我确实做到了(请求已加载到我接受它的默认浏览器并指定了我想使用的帐户)。但是,无法检查该授权;我的 google 帐户数据仅包含 google+ 应用程序的应用程序和活动日志;我没有在列表中找到我的应用程序。那么在哪里可以查看我没有登录的地方呢?

IOException: 401 Unauthorized
com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
at      com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:423)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
at ScreenRecordingExample.UploadToYoutube(ScreenRecordingExample.java:356)

【问题讨论】:

    标签: youtube-api google-api google-api-java-client


    【解决方案1】:

    好的,我发现问题是由于privacyStatus值不正确引起的:

    我有

    status.setPrivacyStatus("listed");
    

    在我的代码中,虽然似乎只有 public、unlisted 和 private 是可能的值

    【讨论】:

      【解决方案2】:

      不幸的是,UPD-2 问题以我不知道具体如何解决的方式解决了:

      我注意到,在我的代码示例中有一行

      return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("user");
      

      我已将“用户”替换为我的 google 用户名(但实际上我不确定这是不是真正需要的东西)。替换后,授权尝试再次开始(默认浏览器加载了接受/拒绝页面,我应该选择两个帐户之一)。由于我有两个账号,一个是原来的youtube一个,一个是普通的google一个,上次我选择了google的一个,出现401错误,这次我选择了youtube的一个。

      这样,问题就解决了。由于正确的用户名而不是“用户”或正确的帐户选择,我仍然不知道这样做。如果有人知道真相,请发表评论!

      【讨论】:

        猜你喜欢
        • 2011-07-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-15
        • 1970-01-01
        • 2021-05-17
        • 1970-01-01
        • 2013-02-18
        相关资源
        最近更新 更多