程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了调试 youtube 数据 API? (评分)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决调试 youtube 数据 API? (评分)?

开发过程中遇到调试 youtube 数据 API? (评分)的问题如何解决?下面主要结合日常开发的经验,给出你关于调试 youtube 数据 API? (评分)的解决方法建议,希望对你解决调试 youtube 数据 API? (评分)有所启发或帮助;

我已经复制并粘贴了此处为 Js 提供的评级 API 代码。 https://developers.google.com/youtube/v3/docs/videos/rate?hl=es&apix_params=%7B%22id%22%3A%22O8IvzIs1s5Y%22%2C%22raTing%22%3A%22none%22%7D&apix=true

几天前它可以工作,但现在我无法让它工作。认证似乎正在发生,但评级部分不会改变评级也不会失败。我什至没有收到 2 条 console.log 消息中的任何一条。

我正在通过 API 中授权的 localhost:8000 (http) 对其进行测试。

HTML 相关代码为:

  <button type="submit" onclick="authenticate().then(loadClIEnt)" class="btn btn-block btn-lg btn-priMary">Authorize me!</button>
  <button type="submit" onclick="execute()" class="btn btn-block btn-lg btn-priMary">Rate it!</button>

Js 部分是:

  <!-- From: https://developers.Google.com/youtube/v3/docs/vIDeos/rate?APIx=true#try-it -->
  <script src="https://APIs.Google.com/Js/API.Js"></script>
  <script>
    /**
     * Sample JavaScript code for youtube.vIDeos.getraTing
     * See instructions for running APIs Explorer code samples locally:
     * https://developers.Google.com/explorer-Help/guIDes/code_samples#JavaScript
     */

    function authenticate() {
      return gAPI.auth2.getAuthInstance()
          .signIn({scope: "https://www.GoogleAPIs.com/auth/youtube https://www.GoogleAPIs.com/auth/youtube.force-ssl https://www.GoogleAPIs.com/auth/youtubepartner"})
          .then(function() { console.log("Sign-in successful"); },function(err) { console.error("Error signing in",err); });
    }
    function loadClIEnt() {
      gAPI.clIEnt.setAPIKey("MY API KEY");
      return gAPI.clIEnt.load("https://content.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() {
      console.log("Pasa")
      return gAPI.clIEnt.youtube.vIDeos.rate({
        "ID": "VIDEOID to rate","raTing": "dislike"
      }).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: "<CLIENT ID>"});
    });
  </script>

注意:我已经替换了凭据和视频 ID。

编辑:

@Nik,在 firefox 中测试给了我这个:TypeError: gAPI.clIEnt.youtube is undefined [了解更多] 家:286:7 执行 http://localhost:8000/home:286:7 onclick gAPI 没有初始化?

我正在缩小范围。我的按钮在标题标签中的位置.... 将按钮移出标题。有没有人对此有解释。 Js 变量是否有与 HTML 标签相关的 reduce 范围?

解决方法

实际上,它并没有失败,它正在对视频进行评级,但 API 没有发送任何响应。它正在发送状态 204 这意味着:

The http 204 No Content success status response code inDicates that a request has succeeded,but that the client doesn't need to navigate away from its current page.

注意:视频ID要正确

,

很抱歉打扰您@Rahul Arora,@Nik。现在我知道出了什么问题。与 HEADER 标签无关。

我的按钮在表单中!:

<form>
<button type="submit" onclick="authenticate().then(loadClient)" class="btn btn-block btn-lg btn-priMary">Authorize me!</button>
  <button type="submit" onclick="execute()" class="btn btn-block btn-lg btn-priMary">Rate it!</button>
</form>

并且表单已提交,因此在执行时丢失了经过gapi验证的实例。

是我的错!我修改了一个 HTML 模板,但没有意识到表单中的按钮。我张贴这个以防其他人犯同样的愚蠢错误!

大佬总结

以上是大佬教程为你收集整理的调试 youtube 数据 API? (评分)全部内容,希望文章能够帮你解决调试 youtube 数据 API? (评分)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。