首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从github gist API获取公共gist文件名

如何从github gist API获取公共gist文件名
EN

Stack Overflow用户
提问于 2021-02-26 19:38:08
回答 1查看 110关注 0票数 0

我正在尝试从github gist API获取文件名,下面的输出是我调用gist api.But时得到的,问题是我如何从输出中获取文件名。因为filename在files下,所以我想显示filename。那么我该怎么做呢。我是API的新手,所以只能显示url,id等。

代码语言:javascript
复制
 {
        "url": "https://api.github.com/gists/41da54b03986886e1a4e57c8cdb38dc2",
        "forks_url": "https://api.github.com/gists/41da54b03986886e1a4e57c8cdb38dc2/forks",
        "commits_url": "https://api.github.com/gists/41da54b03986886e1a4e57c8cdb38dc2/commits",
        "id": "41da54b03986886e1a4e57c8cdb38dc2",
        "node_id": "MDQ6R2lzdDQxZGE1NGIwMzk4Njg4NmUxYTRlNTdjOGNkYjM4ZGMy",
        "git_pull_url": "https://gist.github.com/41da54b03986886e1a4e57c8cdb38dc2.git",
        "git_push_url": "https://gist.github.com/41da54b03986886e1a4e57c8cdb38dc2.git",
        "html_url": "https://gist.github.com/41da54b03986886e1a4e57c8cdb38dc2",
        "files": {
          "telegram-white.svg": {
            "filename": "telegram-white.svg",
            "type": "image/svg+xml",
            "language": "SVG",
            "raw_url": "https://gist.githubusercontent.com/cmschandan/41da54b03986886e1a4e57c8cdb38dc2/raw/16b1aac41526997d87400f33ad9912d511faf7a4/telegram-white.svg",
            "size": 1266
          }
        },
        "public": true,
        "created_at": "2020-12-11T12:58:59Z",
        "updated_at": "2020-12-11T12:59:46Z",
        "description": "",
        "comments": 0,
        "user": null,
        "comments_url": "https://api.github.com/gists/41da54b03986886e1a4e57c8cdb38dc2/comments",
        "owner": {
          "login": "cmschandan",
          "id": 21227329,
          "node_id": "MDQ6VXNlcjIxMjI3MzI5",
          "avatar_url": "https://avatars.githubusercontent.com/u/21227329?v=4",
          "gravatar_id": "",
          "url": "https://api.github.com/users/cmschandan",
          "html_url": "https://github.com/cmschandan",
          "followers_url": "https://api.github.com/users/cmschandan/followers",
          "following_url": "https://api.github.com/users/cmschandan/following{/other_user}",
          "gists_url": "https://api.github.com/users/cmschandan/gists{/gist_id}",
          "starred_url": "https://api.github.com/users/cmschandan/starred{/owner}{/repo}",
          "subscriptions_url": "https://api.github.com/users/cmschandan/subscriptions",
          "organizations_url": "https://api.github.com/users/cmschandan/orgs",
          "repos_url": "https://api.github.com/users/cmschandan/repos",
          "events_url": "https://api.github.com/users/cmschandan/events{/privacy}",
          "received_events_url": "https://api.github.com/users/cmschandan/received_events",
          "type": "User",
          "site_admin": false
        },
        "truncated": false
      },
EN

回答 1

Stack Overflow用户

发布于 2021-08-26 09:38:00

如果你使用的是JavaScript,那么你可以这样做:

代码语言:javascript
复制
// `getGitHubGist` is a function that I assume you already 
// implemented which fetches your desired gist.
const gist = await getGitHubGist();

// Get an array of filename strings
const filenames = Object.keys(gist.files);

// Get an array of all the file details
const files = Object.values(gist.files);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66385169

复制
相关文章

相似问题

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