Youtube api I';我在用google java客户端上传到Youtube时遇到了麻烦:“我的;无效值:列出的不是有效值";
我正在尝试使用示例上传视频 我已在youtube控制台上成功注册,并已在 我已经安装了秘密,所以我的应用程序可以访问它们;一切都编译得很好,但当程序执行时,我会发现奇怪的错误:Youtube api I';我在用google java客户端上传到Youtube时遇到了麻烦:“我的;无效值:列出的不是有效值";,youtube-api,google-api,google-api-java-client,Youtube Api,Google Api,Google Api Java Client,我正在尝试使用示例上传视频 我已在youtube控制台上成功注册,并已在 我已经安装了秘密,所以我的应用程序可以访问它们;一切都编译得很好,但当程序执行时,我会发现奇怪的错误: GoogleJsonResponseException code: 400 : Invalid value for: listed is not a valid value com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad
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)
我找不出是怎么回事;由于请求本身被深度封装,我无法理解请求有什么问题
UPD
多亏了
System.out.println(videoInsert.getHttpContent().toString());
在前插入的呼叫
Video returnedVideo = videoInsert.execute();
在示例代码中,我得到了JSOn格式并发送到google is
{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)
好的,我发现出现问题的原因是privacyStatus值不正确: 我有
status.setPrivacyStatus("listed");
在我的代码中,似乎只有public、unlisted和private才是可能的值,UPD-2问题不幸地以我不知道具体如何解决的方式得到了解决: 我注意到,在我的代码示例中有一行
return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("user");
我已经用我的谷歌用户名替换了“user”(但实际上我不确定这是不是真的需要)。更换后,再次开始授权尝试(默认浏览器加载了接受/拒绝页面,我应该在其中选择两个帐户中的一个)。因为我有两个账户,一个是原始的youtube账户,另一个是普通的google账户,在上次尝试时我选择了google账户,但出现了401错误,所以这次我选择了youtube账户
因此,在那之后,问题就解决了。我仍然不知道是因为正确的用户名而不是“用户”,还是因为正确的帐户选择。如果有人知道真相,请发表评论