Youtube Data-api代码停止工作 - 更新视频元数据功能

时间:2017-09-09 08:50:16

标签: java youtube youtube-api youtube-data-api

开发基于Java Web的应用程序。我想在哪里更新我的YouTube视频标题,说明或标签。早期的代码工作得非常好。突然,当我发出执行请求时它已停止工作。大多数情况下,我使用了java中给出的代码示例。下面是我从主java文件中获取的代码示例。我在构造函数中发送值。我已经大胆提出错误的界限。是否还有其他人突然面临这一挑战。什么是决议。

错误--- 出现服务错误:400:请求元数据无效。 14:01:20.567 [main] ERROR com.analytics.youtube.UpdateYoutubeContent - 发生了服务错误:400:请求元数据无效。

this.setConnection(Lists.newArrayList("https://www.googleapis.com/auth/youtube"),"updatevideo");
            logger.info("After Setting Connection");
            YouTube.Videos.List listVideosRequest = this.ytConn.videos().list("snippet").setId(this.sId);
            VideoListResponse listResponse = listVideosRequest.execute();
            List<Video> videoList = listResponse.getItems();
            if (videoList.isEmpty()) {
                //System.out.println("Can't find a video with ID: " + videoId);
                throw (new Exception("Can't find a video with ID: "+this.sId));
            }
            Video video = videoList.get(0);
            VideoSnippet snippet = video.getSnippet();
            if(this.sTitle != ""){
                snippet.setTitle(this.sTitle);
                System.out.println("Title");
            }
            if(this.sDescription != ""){
                snippet.setDescription(this.sDescription);   
                System.out.println("Description");
            }
            if(this.sTags.get(0) != ""){
                snippet.setTags(this.sTags);
                System.out.println("Tags");
            }
            System.out.println(this.sTitle);
            System.out.println(this.sDescription);
            System.out.println(this.sTags.get(0));
//            snippet.

            YouTube.Videos.Update updateVideosRequest = this.ytConn.videos().update("snippet", video);
            **Video videoResponse = updateVideosRequest.execute();**


            logger.info("Before Catch");
        }catch (GoogleJsonResponseException e) {
            logger.error("There was a service error: " + e.getDetails().getCode() + " : "
                    + e.getDetails().getMessage());
            throw e;
        }
        catch(Exception ex){ logger.info("Inside Catch");
            logger.error("Error Message--"+ ex.getMessage() + "  Cause--" + ex.getCause());
            throw ex;
        }

1 个答案:

答案 0 :(得分:0)

以下是您遇到的possible errors,因为我无法在代码中看到粗线。

  

<强> commentThreads

     

下表列出了API返回的错误消息   响应与commentThreads资源相关的调用。这些方法   也可能会返回Common errors部分中列出的错误。

     
      
  • commentThreads.insert
  •   
  • commentThreads.update
  •   
     

<强>评论

     

下表列出了API返回的错误消息   响应与评论资源相关的调用。这些方法可以   还会返回Common errors部分中列出的错误。

     
      
  • comments.insert
  •   
  • comments.update
  •   
     

<强>视频

     

下表列出了API返回的错误消息   响应与视频资源相关的呼叫。这些方法可以   还会返回Common errors部分中列出的错误。

     
      
  • videos.insert - 请求元数据无效。如果请求更新视频snippet部分,则会出现此错误   资源但未为代码段标题设置值   和 snippet.categoryId 属性。

  •   
  • videos.update - 请求元数据无效。如果请求更新视频snippet部分,则会出现此错误   资源,但没有为 snippet.title 和。设置值    snippet.categoryId 属性。

  •