PHP code example of mpscholten / github-api

1. Go to this page and download the library: Download mpscholten/github-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mpscholten / github-api example snippets




use MPScholten\GitHubApi\Github;

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



use MPScholten\GitHubApi\Github;

$github = Github::create();

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

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

$user->getEmail();
$user->getName();
$user->getUrl();
$user->getAvatarUrl();
// ...

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

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

// with the 'user:email' oauth scope
$user->getPrimaryEmail();
$user->getEmails();

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

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

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

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

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

// this is equals to https://github.com/search?q=language%3Aphp+&type=Repositories&ref=searchresults
foreach (Github::create()->getSearch()->findRepositories('language:php') as $repo) {
    $repo->getName();
    // ...
}

foreach ($repository->getReleases() as $release) {
    $release->getUrl(); // https://github.com/octocat/Hello-World/releases/v1.0.0
    $release->getUrl('zipball'); // https://api.github.com/repos/octocat/Hello-World/zipball/v1.0.0
    $release->getCreatedAt()->format('Y-m-d H:i:s');
}

foreach ($repository->getIssues() as $issue) {
    $issue->getLabels()->count();
    
    $issue->getNumber(); // 2
    $issue->getAuthor()->getLogin(); // "mpscholten"
    $issue->getTitle(); // "Add Issue-API"
    $issue->getBody();
    
    $issue->isOpen();
    $issue->isClosed();
    $issue->getState();
}

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



use MPScholten\GitHubApi\Github;

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