检索访问令牌时出错:TypeError:无法读取未定义的属性“project_id”

2024-05-04

我是扣扣新手。

首次登录后通过: 扣登录 我能够登录 script.google.com 接下来,我创建了一个项目并通过以下方式推送文件: 扣推

现在,我已使用以下方式注销: 扣注销

这里需要帮助:现在,如果我正在尝试:

clasp 登录 --creds ./.clasp.json

我收到“检索访问令牌时出错:TypeError:无法读取未定义的属性‘project_id’”。

请指导我如何通过 --creds 登录?


TLDR:您正在使用配置文件(.clasp.json),而不是凭证文件(creds.json或其他)从 Google Cloud 项目控制台。


当您登录时,凭据的默认存储位于名为的文件中.clasprc.json in the ~目录 (C:\Users\<user>\在 Windows 上):

$ clasp login
Logging in globally...
???? Authorize clasp by visiting this url:
https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&.....

Authorization successful.

Default credentials saved to ~\.clasprc.json (C:\Users\<user>\.clasprc.json).

请注意,该文件(.clasprc.json) 不等于.clasp.json.

clasprc.json https://github.com/google/clasp/blob/2.0.1/src/auth.ts#L19-L43 format:

据称,该文件的内容取决于身份验证类型(全局或本地):

// GLOBAL: clasp login will store this (~/.clasprc.json):
 {
   "access_token": "XXX",
   "refresh_token": "1/k4rt_hgxbeGdaRag2TSVgnXgUrWcXwerPpvlzGG1peHVfzI58EZH0P25c7ykiRYd",
   "scope": "https://www.googleapis.com/auth/script.projects https://www.googleapis.com/auth/script ...",
   "token_type": "Bearer",
   "expiry_date": 1539130731398
 }

本地身份验证存储客户端机密/等,如果您打算使用,通常需要clasp run https://github.com/google/clasp/tree/2.0.1#run通过 Google Apps 脚本 API 执行函数。

// LOCAL: clasp login will store this (./.clasprc.json):
 {
   "token": {
     // as above
   },
   // Settings
   "oauth2ClientSettings": {
     "clientId": "807925367021-infvb16rd7lasqi22q2npeahkeodfrq5.apps.googleusercontent.com",
     "clientSecret": "9dbdeOCRHUyriewCoDrLHtPg",
     "redirectUri": "http://localhost"
   },
   "isLocalCreds": true
}

(实际上,两个文件的格式都是LOCAL文件--属​​性token, oauth2ClientSettings, and isLocalCreds——虽然价值isLocalCreds对于全局登录将为 false。)

扣子.json https://github.com/google/clasp/blob/2.0.1/README.md#project-settings-file-claspjson format:

{
  "scriptId": "",
  "rootDir": "build/",
  "projectId": "project-id-xxxxxxxxxxxxxxxxxxx",
  "fileExtension": "ts",
  "filePushOrder": ["file1.ts", "file2.ts"]
}

注意clasp.json is 脚本文件的配置 and clasprc.json is stored 用户的凭证/授权. Neither其中是用于本地登录的相应凭证文件。

解决错误

您收到的特定错误是由于您提供了不正确的文件而导致的。您提供的“凭据”文件不具有所需的属性,因此当 clasp 尝试从该属性读取 https://github.com/google/clasp/blob/b5701c70be348fd9d2e2b4eb85e670c3298d9e6e/src/auth.ts#L92

  console.log(LOG.CREDS_FROM_PROJECT(options.creds.installed.project_id));

你得到错误:

检索访问令牌时出错:TypeError:无法读取未定义的属性“project_id”

您可以从 Apps 脚本项目的 Google Cloud 项目页面获取正确的凭据文件,即https://console.cloud.google.com/apis/credentials?authuser=0&project=<some project id>

该文件的格式为:

{
    "installed":{
        "client_id":"<stuff>.apps.googleusercontent.com",
        "project_id":"<some project id>",
        "auth_uri":"https://accounts.google.com/o/oauth2/auth",
        "token_uri":"https://oauth2.googleapis.com/token",
        "auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs",
        "client_secret":"<more stuff>",
        "redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]
    }
}

如果您的凭据文件不具有该格式,则无法使用它在本地登录。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

检索访问令牌时出错:TypeError:无法读取未定义的属性“project_id” 的相关文章

随机推荐

  • 为什么 SDL 在 Mac 上比 Linux 上慢得多?

    我正在研究使用 SDL2 渲染的单线程图形程序 https github com TurkeyMcMac intergrid 请参阅末尾的较小示例 它既可以在旧的 Linux 机器上运行 也可以在不太旧的 Mac 上运行 Linux 计算机
  • Cocos2d:CCSpriteBatch 节点是否仅绘制可见属性设置为 true 的精灵?

    CCSpriteBatch 节点是否仅绘制可见属性设置为 true 的精灵 或者它也考虑屏幕尺寸 换句话说 如果节点内的精灵位于屏幕之外 opengl 绘制调用的性能是否会反映这一点 不 不 CCSpriteBatchNode 始终绘制所有
  • 多处理中的共享内存

    我有三个大清单 第一个包含位数组 模块位数组 0 8 0 另外两个包含整数数组 l1 bitarray 1 bitarray 2 bitarray n l2 array 1 array 2 array n l3 array 1 array
  • mysql 时钟

    我有一个包含以下元素的时钟表 id pk action emp id fk time 如果我通过了 如何选择最新的动作emp id到查询 id emp id action current time 1 1 clockin 2012 01 2
  • IE9 是否支持 CSS3 ::before 和 ::after 伪元素?

    On 这个 MS 兼容性表 http msdn microsoft com en us library cc351024 28v vs 85 29 aspx它说 IE9不支持伪元素 before and after 但当我尝试时 似乎确实
  • 将数据作为 RDD 保存回 Cassandra

    我试图从 Kafka 读取消息 处理数据 然后将数据添加到 cassandra 中 就像它是 RDD 一样 我的麻烦是将数据保存回 cassandra 中 from future import print function from pys
  • 使用基类活动将多个活动(选项卡)绑定到服务

    发帖后发现这些 http code google com p android issues detail id 2665 http code google com p android issues detail id 2665http co
  • Javascript时间转换正则表达式

    我有一种使用 Net 中的正则表达式来转换时间的方法 例如 1h 20m 格式为双倍 就这个 public static double GetTaskHours this string tmpHours Double taskHours 0
  • 在 Pygame 中缩放图像/矩形

    是否可以在 pygame txt 内部 缩放 矩形 有点像当你在桌面上缩放窗口时 我想知道你如何在 pygame 中做到这一点 您的光标将控制矩形的大小 我使用 skrx 方法并尝试对 2 个矩形执行此操作 if evnt type MOU
  • Facebook应用程序白名单流程

    有谁知道将 FB 应用程序列入白名单以启用某些功能的过程吗 我看到很少有人问同样的问题 但没有答案 FB 有处理白名单申请的联系人吗 没有申请白名单的公共流程 与大多数公司一样 Facebook 可能拥有少量私有 API 这些 API 仅供
  • pandas - 将字符串转换为字符串列表[重复]

    这个问题在这里已经有答案了 我有这个 file csv 文件可以用 pandas 读取 Title Tags T1 Tag1 Tag2 T1 Tag1 Tag2 Tag3 T2 Tag3 Tag1 using df pd read csv
  • Ruby:注释“frozen_string_literal: true”有什么作用?

    这是rspecbinstub 在我的项目目录中 usr bin env ruby begin load File expand path spring FILE rescue LoadError end frozen string lite
  • 如何在 Chrome 开发者工具的控制台中启用下划线?

    我正在使用 Angular2 和下划线 import as from underscore 我也想在 Chrome 控制台窗口中使用下划线库 即使我确实在代码中间中断 并尝试使用 但我得到了 未定义 错误 我可以在 Chrome 控制台窗口
  • Jquery .ajax method =“post”但$_POST为空

    ajax method post url save php data id 453 action test beforeSend function complete function success function html mydiv
  • 具有 UI 自动化和 .net 的数据网格内容

    我在使用 UI 自动化读取外部应用程序中的数据网格内容时遇到一些问题 并且可以使用一些指针 这是我到目前为止所拥有的 int id System Diagnostics Process GetProcessesByName Book 0 I
  • 使用Log4j在日志中输出Spark应用程序id

    我有一个用于 Spark 应用程序的自定义 Log4j 文件 我想输出 Spark 应用程序 ID 以及消息和日期等其他属性 因此 JSON 字符串结构如下所示 name time date level thread message app
  • React.js 关于监听组件窗口事件的最佳实践

    我根据几个 React js 组件在视口中的位置对它们进行动画处理 如果组件位于视口中 则将不透明度动画设置为 1 如果不在视口中 则将其不透明度动画设置为 0 我正在使用getBoundingClient s top and bottom
  • 查看所有定义的变量

    我目前正在 python shell 中进行计算 我想要的是 Matlab 风格的列表 您可以在其中看到已定义的所有变量 这样我就知道我使用了哪些名称 它们的值等 有办法吗 我该怎么做 您可以使用一些东西 dir 将为您提供范围内变量的列表
  • 带有 Hamcrest 匹配器的 TestNG 软断言

    我想在 TestNG 测试中使用 Hamcrest 匹配器 并专门使用软断言 我怎样才能做到这一点 我知道我可以在测试中使用 Hamcrest 的断言 例如 assertThat actual containsInAnyOrder expe
  • 检索访问令牌时出错:TypeError:无法读取未定义的属性“project_id”

    我是扣扣新手 首次登录后通过 扣登录 我能够登录 script google com 接下来 我创建了一个项目并通过以下方式推送文件 扣推 现在 我已使用以下方式注销 扣注销 这里需要帮助 现在 如果我正在尝试 clasp 登录 creds