Github API 库的JSON文件格式

1. 获取所有库文件

curl -u zhu126fang https://api.github.com/user/repos

2. 截取其中一个库的JSON文件

{
    "id": 28468054,
    "name": "raspberry",
    "full_name": "zhu126fang/raspberry",
    "owner": {
      "login": "zhu126fang",
      "id": 10016241,
      "avatar_url": "https://avatars.githubusercontent.com/u/10016241?v=3",
      "gravatar_id": "",
      "url": "https://api.github.com/users/zhu126fang",
      "html_url": "https://github.com/zhu126fang",
      "followers_url": "https://api.github.com/users/zhu126fang/followers",
      "following_url": "https://api.github.com/users/zhu126fang/following{/other_user}",
      "gists_url": "https://api.github.com/users/zhu126fang/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/zhu126fang/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/zhu126fang/subscriptions",
      "organizations_url": "https://api.github.com/users/zhu126fang/orgs",
      "repos_url": "https://api.github.com/users/zhu126fang
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个Java代码示例,使用GitHub APIGitHub中读取文件内容: ```java import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.Base64; public class GitHubFileReader { public static void main(String[] args) throws IOException { // GitHub API URL String apiUrl = "https://api.github.com/repos/{owner}/{repo}/contents/{path}"; // GitHub repository information String owner = "github"; String repo = "gitignore"; String path = "Java.gitignore"; // Replace placeholders with actual values apiUrl = apiUrl.replace("{owner}", owner) .replace("{repo}", repo) .replace("{path}", path); // Set up HTTP connection URL url = new URL(apiUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.setRequestProperty("Accept", "application/vnd.github.v3+json"); // Set up authentication if needed String username = "username"; String token = "token"; String auth = username + ":" + token; byte[] encodedAuth = Base64.getEncoder().encode(auth.getBytes(StandardCharsets.UTF_8)); String authHeaderValue = "Basic " + new String(encodedAuth); connection.setRequestProperty("Authorization", authHeaderValue); // Read response InputStream responseStream = connection.getInputStream(); String response = new String(responseStream.readAllBytes(), StandardCharsets.UTF_8); // Extract content from response int start = response.indexOf("\"content\": \"") + 12; int end = response.indexOf("\",", start); String content = response.substring(start, end); // Decode content String decodedContent = new String(Base64.getDecoder().decode(content), StandardCharsets.UTF_8); // Print content System.out.println(decodedContent); } } ``` 这个代码示例假设你已经有了GitHub API的访问令牌,用于身份验证。如果你没有访问令牌,你需要创建一个并将其传递到HTTP请求中,以便进行身份验证。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值