GitHub is a popular web-based Git repository hosting service, which offers all of the distributed revision control and source code management functionality of Git as well as adding its own features.
Since may 2013, GitHub announced Octokit, a new lineup of GitHub-maintained client libraries for the GitHub API. This means Octokit provide officially 3 libraries written in Ruby, Objective-C and .NET.
However, third-party libraries are available in other languages and particularly in PHP. At this time you can find at least 9 libraries to interact with GitHub API in PHP but none of this libraries provide a full support for all GitHub API features.
This library as been developed to help you to use all the features of GitHub API v3 easily as possible. This library, like the GitHub API is sparate in 2 distinct parts:
This library provide the next features:
To run this library in your web server, you’ll need the most recent PHP version of the branch 5.6.x. for some security and dependencies reasons.
This library is only compatible with PHP 5.6.1 or above. So please upgrade your PHP version if you have a lower version installed.
You will also need the cURL extension enabled in your web server.
This library use some dependencies to work with.
Here are the dependencies this library need to be installed with:
To get the latest version of this GitHub API library simply use composer.
composer.json
file:1$ php composer.phar require scion/githubapi
1$ php composer.phar install
1<?php
2// This file is generated by Composer
3require 'vendor/autoload.php';
4
5// Create a Client object
6$client = new \Scion\GitHub\Client();
Webhooks allow you to build or set up integrations which subscribe to certain events on GitHub.com.
Complete documentation is available at https://developer.github.com/webhooks/.
For using a WebHook, you need an instance of Scion\GitHub\WebHook
class like:
1<?php
2// This file is generated by Composer
3require 'vendor/autoload.php';
4
5// Creating WebHook instance
6$webhook = new \Scion\GitHub\WebHook();
This library supports all authentications provided by the GitHub API v3. You can use the Basic Authentication, OAuth Token or the OAuth2 Key/Secret pair authentication for the Client and WebHook classes, like described here:
1// Username only
2$client->setHttpAuth('username');
3
4// Username & password
5$client->setHttpAuth('username', 'password');
Go to Authorized applications to Generate new token
, then you will be able to provide your 'token'.
1// sent in userpwd
2$client->setToken('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
3
4// sent in a header
5$client->setToken('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', \Scion\Github\Client::OAUTH2_HEADER_AUTH);
6
7// sent as a parameter
8$client->setToken('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', \Scion\Github\Client::OAUTH2_PARAMETERS_AUTH);
Go to Authorized applications to Register new application
, then you will be able to provide yours client_id
and client_secret
.
1$client->setClientId(''); // Set client_id
2$client->setClientSecret(''); // Set client_secret
You can find the full documentation of this library in the wiki section of the GitHub repository.
© 2013-2024 All rights reserved.