javascript - Google 跟踪代码管理器 API 示例在控制台中抛出 "Uncaught RangeError: Maximum call stack size exceeded"错误

标签 javascript api google-api google-tag-manager

我从 Google 跟踪代码管理器 API 文档中获取了“完整示例”的代码:

https://developers.google.com/tag-manager/api/v2/devguide#example

我将 TODO 更改为我的客户端 ID,并更新了 ACCOUNT_PATHCONTAINER_NAMEWORKSPACE_NAME,但是当我运行它时我只是在控制台中看到一个空白页面。

Console error

我缺少哪些步骤?如果有影响的话,我还在本地主机上运行该文件。

最佳答案

发生这种情况是因为第 47 行的 checkAuth() 函数在递归循环中调用自身。

我通过更改调用函数的名称来修复它-

function checkAuthVal(immediate) {
  var authorizeCheckPromise = new Promise((resolve) => {
    gapi.auth.authorize(
      { client_id: CLIENT_ID, scope: SCOPES.join(' '), immediate: immediate },
      resolve);
  });
  authorizeCheckPromise
      .then(handleAuthResult)
      .then(loadTagManagerApi)
      .then(runTagManagerExample)
      .catch(() => {
        console.log('You must authorize any access to the api.');
      });
}

/**
 * Check if current user has authorization for this application.
 */
function checkAuth() {
  checkAuthVal(true);
}

这成功了!

关于javascript - Google 跟踪代码管理器 API 示例在控制台中抛出 "Uncaught RangeError: Maximum call stack size exceeded"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47597629/

相关文章:

javascript - Angular 4 和 bootstrap - 将容器类添加到组件选择器

javascript - 在 Laravel 中嵌入 Google Analytics

javascript - Angular UI-Grid TypeError : Cannot set property 'data' of undefined. 发送来自服务的 promise 和未定义的数据

javascript - 如何撤销 Identity API token (Chrome 扩展)

python - 如何在 GAE/Python 上进行 'access_type=offline'/server-only OAuth2 操作?

javascript - 将日期绑定(bind)到 Angular DatePicker 组件的 Kendo UI

c# - 使用通用/实用程序库

c++ - C++ STL 是 C++ API 吗?

google-apps-script - Google Classroom Apps 脚本 - CourseWork.list 权限错误

php - YouTube 数据 API : authenticate as a resource owner