首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Youtube CommentThreads api插入不工作

Youtube CommentThreads api插入不工作
EN

Stack Overflow用户
提问于 2022-06-14 06:19:22
回答 1查看 167关注 0票数 0

我试图使用Youtube api v3对视频进行评论并得到这个错误,但根据文档,我的请求数据是正确的。这是我的密码。使用oauth代码设置access_token,如下所示

Oauth.setCredentials(令牌);

代码语言:javascript
运行
复制
 var channelId = "UCq-Fj5jknLsUf-MWSy4_brA";
                var request = Youtube.commentThreads.insert({
                          "part": [
                                    "snippet"
                          ],
                          "resource": {
                                    "snippet": {
                                              "videoId": "qfuFeUnAm8E",
                                              "topLevelComment": {
                                                        "snippet": {
                                                                  "textOriginal": "best video"
                                                        }
                                              },
                                              "channelId": channelId
                                    }
                          }
                }, (err, data) => {
                          if (err) {
                                    console.log(err, 'errerrerr')
                          }
                          if (data) {
                                    console.log(data, 'datadata');
                          }
                });

这是我得到回报的错误

代码语言:javascript
运行
复制
  errors: [
{
  message: "The API server failed to successfully process the request. While this can be a transient error, it usually indicates that the request's input is invalid. Check the structure of the <code>commentThread</code> resource in the request body to ensure that it is valid.",
  domain: 'youtube.commentThread',
  reason: 'processingFailure',
  location: 'body',
  locationType: 'other'
}

]

这是每次生成身份验证或授权代码。

代码语言:javascript
运行
复制
"tokens": {
    "access_token": "[redacted]",
    "scope": "https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/youtubepartner https://www.googleapis.com/auth/youtube.force-ssl https://www.googleapis.com/auth/youtube.upload",
    "token_type": "Bearer",
    "expiry_date": 1655195240477
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-06-14 08:15:29

我认为您应该考虑在试试看中测试您的插入,您创建的对象看起来根本不对。

您应该咨询注释资源以获得适当的正文格式。

代码语言:javascript
运行
复制
<script src="https://apis.google.com/js/api.js"></script>
<script>
  /**
   * Sample JavaScript code for youtube.comments.insert
   * See instructions for running APIs Explorer code samples locally:
   * https://developers.google.com/explorer-help/code-samples#javascript
   */

  function authenticate() {
    return gapi.auth2.getAuthInstance()
        .signIn({scope: "https://www.googleapis.com/auth/youtube.force-ssl"})
        .then(function() { console.log("Sign-in successful"); },
              function(err) { console.error("Error signing in", err); });
  }
  function loadClient() {
    gapi.client.setApiKey("YOUR_API_KEY");
    return gapi.client.load("https://www.googleapis.com/discovery/v1/apis/youtube/v3/rest")
        .then(function() { console.log("GAPI client loaded for API"); },
              function(err) { console.error("Error loading GAPI client for API", err); });
  }
  // Make sure the client is loaded and sign-in is complete before calling this method.
  function execute() {
    return gapi.client.youtube.comments.insert({
      "resource": {
        "snippet": {
          "videoId": "qfuFeUnAm8E",
          "channelId": "UCq-Fj5jknLsUf-MWSy4_brA"
        }
      }
    })
        .then(function(response) {
                // Handle the results here (response.result has the parsed body).
                console.log("Response", response);
              },
              function(err) { console.error("Execute error", err); });
  }
  gapi.load("client:auth2", function() {
    gapi.auth2.init({client_id: "YOUR_CLIENT_ID"});
  });
</script>
<button onclick="authenticate().then(loadClient)">authorize and load</button>
<button onclick="execute()">execute</button>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72612302

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档