Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Build Status Latest Stable Version License

An easy to use github api client for PHP.


You need php 5.4 or higher to use this library.


  • very easy to use and ide-friendly
  • pure object oriented interface
  • automatically handled pagination
  • psr-2

Get started

Install via composer: composer require mpscholten/github-api v0.3

    "require": {
        "mpscholten/github-api": "v0.3"



To use oauth just pass your oauth token to Github::create() like this.


use MPScholten\GitHubApi\Github;

$github = Github::create('oauth token');

No authentication

If you want to use the public api without any authentication you can do this by just calling Github::create without any arguments.


use MPScholten\GitHubApi\Github;

$github = Github::create();

User API

In case you are using oauth you can get the current logged-in user by calling

$user = Github::create('oauth token')->getCurrentUser();

Otherwise you can get users by their github username.

$user = Github::create()->getUser('mpscholten');

With the user object you can now do

// ...

// relations
$user->getRepositories(); // returns an array of Repositories owned by the user

// list the users repositories
foreach ($user->getRepositories() as $repository) {
    echo $repository->getName();

// with the 'user:email' oauth scope

foreach ($user->getEmails() as $email) {
    if ($email->isVerified()) {
        echo $email;

Repository API

$repository = Github::create()->getRepository('mpscholten', 'github-api');

$repository->getOwner(); // returns a user object
$repository->getOwner()->getName(); // chaining 

// list the collaborators of the repo
foreach ($repository->getCollaborators() as $collaborators) {
    echo $collaborators->getName();

Organization API

foreach ($user->getOrganizations() as $org) {
    $org->getName(); // e.g. GitHub
    $org->getLocation(); // e.g. San Francisco

Search API

You can use the search api by calling $github->getSearch()

// this is equals to
foreach (Github::create()->getSearch()->findRepositories('language:php') as $repo) {
    // ...

Release API

foreach ($repository->getReleases() as $release) {
    $release->getUrl(); //
    $release->getUrl('zipball'); //
    $release->getCreatedAt()->format('Y-m-d H:i:s');

Issue API

foreach ($repository->getIssues() as $issue) {
    $issue->getNumber(); // 2
    $issue->getAuthor()->getLogin(); // "mpscholten"
    $issue->getTitle(); // "Add Issue-API"


Don't worry about pagination, all paginated collections are using a custom Iterator so we can automatically load more results if you need them. So you can focus on what you really want to do.

Example This will print you all commits of the repository.

foreach ($repository->getCommits() as $commit) {
    echo $commit->getMessage() . "\n";


It's builtin! By default we will use in-memory caching but you might want to use file caching. Just pass your cache directory to Github::create(), like this


use MPScholten\GitHubApi\Github;

$github = Github::create('oauth token', 'my-cache-dir/');


$ phpunit


Feel free to send pull request!