You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

求助:GitHub API无法获取全部用户及仓库Issue的解决方法

Hey there! Let's walk through how to fix those GitHub API issues you're facing with the atom repository.

Fixing GitHub API Pagination & Full Data Retrieval Problems

1. Why You're Only Getting 30 Issues

GitHub API uses pagination by default, returning 30 items per page—exactly what you're seeing. Even adding filter: all won't bypass this; you have to explicitly handle pagination to grab all results.

How to Fetch All 772 Issues

Here's what you need to adjust in your axios setup:

  • Use the per_page parameter to max out items per page (you can set this to 100, which cuts down on the total number of requests needed)
  • Track the page parameter to iterate through every page until there are no more results left
  • Add authentication with a personal access token—unauthenticated requests have strict rate limits and might not return all data (like private issues, if any exist)

Example Axios Code Snippet

const axios = require('axios');
// Generate a personal access token in your GitHub account settings
const GITHUB_TOKEN = 'your-personal-access-token';
const REPO_DETAILS = { owner: 'atom', repo: 'atom' };
let allIssues = [];
let currentPage = 1;

async function fetchAllIssues() {
  try {
    const response = await axios.get(
      `https://api.github.com/repos/${REPO_DETAILS.owner}/${REPO_DETAILS.repo}/issues`,
      {
        headers: {
          Authorization: `token ${GITHUB_TOKEN}`
        },
        params: {
          filter: 'all',
          state: 'all', // Ensures you get open, closed, and locked issues
          per_page: 100,
          page: currentPage
        }
      }
    );

    // Stop recursion when no more issues are returned
    if (response.data.length === 0) {
      console.log(`Successfully fetched ${allIssues.length} total issues`);
      return allIssues;
    }

    // Add current page's issues to the full list
    allIssues = [...allIssues, ...response.data];
    currentPage++;
    return fetchAllIssues();
  } catch (error) {
    console.error('Error fetching issues:', error.response?.data || error.message);
    throw error;
  }
}

// Kick off the fetch process
fetchAllIssues();

2. Fixing the "Cannot Retrieve All Users" Issue

If you're trying to pull user data (like assignees, issue creators, or contributors), the same pagination rules apply. Plus:

  • Some user profiles might be hidden if they're set to private, or if you don't have authenticated access
  • Endpoints like /repos/{owner}/{repo}/contributors also require per_page and page parameters, along with authentication, to return full results

Key Tips for User Retrieval

  • Always include your personal access token in the Authorization header to avoid rate limits and access full data
  • For user-focused endpoints, use per_page=100 and loop through pages until the response is empty
  • You can also parse the Link header in API responses—it includes direct links to next/previous pages, which can automate pagination instead of incrementing a page counter manually

Critical Things You Might Have Missed

  • Authentication: Unauthenticated requests only get 60 requests per hour, while authenticated ones get 5000—this is non-negotiable for fetching large datasets like 700+ issues
  • state Parameter: Without setting state: 'all', you'll only get open issues by default, even with filter: all
  • Pagination is Mandatory: GitHub never returns all results in a single request for large datasets—you have to loop through pages

内容的提问来源于stack exchange,提问作者Edgardo Gutierrez

火山引擎 最新活动