由于缺少作用域,无法使用GitHub Cli列出projectsV2



当使用projectsV2的GitHub CLI运行GraphQL查询时,我得到一个关于缺少作用域的错误抱怨:

Your token has not been granted the required scopes to execute this query. The 'projectsV2' field requires one of the following scopes: ['read:project'], but your token has only been granted the: ['admin:public_key', 'gist', 'read:org', 'repo'] scopes. Please modify your token's scopes at: https://github.com/settings/tokens.

示例查询:

> gh api graphql -f query='{
organization(login: "MyOrg") {
projectsV2(last: 20) {
nodes {
title
}
}
}
}'

如何提升GitHub的CLI权限?

默认情况下,GitHub的CLI在通过gh auth login进行身份验证时只请求几个作用域。然而,新的项目v2也需要read:project

这个问题可以通过在登录时请求一个额外的作用域来解决,像这样:

> gh auth login --scopes read:project

或者,如果你还需要写项目,你甚至可能需要对项目的完全访问权限,像这样:

> gh auth login --scopes project

注意,您可能需要先注销:gh auth logout

最新更新