All Projects → diversen → simple-php-github-api

diversen / simple-php-github-api

Licence: other
a simple php github api

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to simple-php-github-api

fixtures
Fixtures for all the octokittens
Stars: ✭ 82 (+530.77%)
Mutual labels:  github-api
go-github
Go library for accessing the GitHub v3 API
Stars: ✭ 8,539 (+65584.62%)
Mutual labels:  github-api
SimpleXamarinGraphQL
An iOS and Android app built in Xamarin.Forms demonstrating how to interact with GitHub's GraphQL API
Stars: ✭ 18 (+38.46%)
Mutual labels:  github-api
GitHubReadmeWebTrends
An automated tool created using Azure Functions that double checks each Readme to ensure every repository is leveraging Web Trends
Stars: ✭ 13 (+0%)
Mutual labels:  github-api
github-api-plugin
This plugin packages stock github-api library
Stars: ✭ 20 (+53.85%)
Mutual labels:  github-api
TB
🖖 A simple & cool blog platform, based on GitHub API, designed for Geeks
Stars: ✭ 24 (+84.62%)
Mutual labels:  github-api
github-status-updater
Command line utility for updating GitHub commit statuses and enabling required status checks for pull requests
Stars: ✭ 83 (+538.46%)
Mutual labels:  github-api
geet
Command line interface for performing Git hosting service operations
Stars: ✭ 14 (+7.69%)
Mutual labels:  github-api
github-resume
An instant resume generator using Github.
Stars: ✭ 56 (+330.77%)
Mutual labels:  github-api
github-client
A Frontend Application using Pure Javascript and Github API
Stars: ✭ 21 (+61.54%)
Mutual labels:  github-api
search-github-starred
Full-Text Search the readme, description, homepage and URL of your GitHub starred repository. Use GitHub OAuth 2, React, Redux, Golang (server side), Elasticsearch, Redis.
Stars: ✭ 15 (+15.38%)
Mutual labels:  github-api
top-github-scraper
Scape top GitHub repositories and users based on keywords
Stars: ✭ 40 (+207.69%)
Mutual labels:  github-api
SQLGitHub
💻 SQLGitHub — Managing GitHub organization made easier
Stars: ✭ 34 (+161.54%)
Mutual labels:  github-api
git-down-repo
Download git-repo for any url
Stars: ✭ 50 (+284.62%)
Mutual labels:  github-api
stargazer
A app that gives you some statistics about your public Github repositories.
Stars: ✭ 36 (+176.92%)
Mutual labels:  github-api
github-app
node module to handle authentication for the GitHub Apps API
Stars: ✭ 51 (+292.31%)
Mutual labels:  github-api
Swift-VIPER-iOS
SwiftVIPER is an sample iOS App written in Swift using the VIPER architecture. Also SwiftVIPER is not a strict VIPER architecture.
Stars: ✭ 25 (+92.31%)
Mutual labels:  github-api
social-preview
Generate a stylish meta (social media) preview for your own GitHub repository. A different image is generated for every repository. Use your Github-assigned language colors too!
Stars: ✭ 64 (+392.31%)
Mutual labels:  github-api
benjamincarlson.io
My personal website built with Next.js, Chakra UI, Firebase, and next-mdx-remeote.
Stars: ✭ 102 (+684.62%)
Mutual labels:  github-api
octillect
An Intellectual Octopus for managing your tasks and projects.
Stars: ✭ 14 (+7.69%)
Mutual labels:  github-api

About

Very simple github API for PHP using OAuth. 37 LOC for the API class. And a curl helper class with 84 LOC.

Install simple-php-github-api

php composer.phar require diversen/simple-php-github-api:

Or if you have placed composer.phar in your path as composer

composer require diversen/simple-php-github-api

Brief explantion.

There is really only tree methods you can do. Let us see those three methods first. (Further below is an complete example using the built-in server for easy testing).

  1. Generate an access URL to github.com
$access_config = array (
    'redirect_uri' => GITHUB_CALLBACK_URL,
    'client_id' => GITHUB_ID,
    'state' =>  md5(uniqid()),
    'scope' => 'user' 
);

$api = new githubapi();
$url = $api->getAccessUrl($access_config);
echo "<a href=\"$url\">Github Login</a>";
  1. Callback from github.com
$access_config = array (
    'redirect_uri' => GITHUB_CALLBACK_URL,
    'client_id' => GITHUB_ID,
    'client_secret' => GITHUB_SECRET
);

$api = new githubapi();
$res = $api->setAccessToken($access_config);

if ($res) {
    // OK
    This is where we will call the api
    header("Location: /api_call.php");
} else {
    // Not OK. echo errors
    echo "Could not get access token. Errors: <br />";
    print_r($api->errors);
}
  1. API call

For full listing see: https://developer.github.com/v3/

// We have a access token and we can now call the api: 
$api = new githubapi();

// Simple call - API get current users credentials
// This can also be done without scope

// example
// $command = '/user', 
// $request = 'GET', 'POST' or 'PATCH' or 'DELETE' etc. Se API: 
// $post = variables to POST array

$command = "/user";
$res = $api->apiCall($command, $request = null, $post = null);
if (!$res) {
    print_r($api->errors); 
    die;
} else {
    print_r($res);
}

Full example

Example you can run right away using the built-in PHP-server.

Make a github app

Log into github.com

Register a new application at https://github.com/settings/developers

You will see something like this:

My settings

Create your app.

Enter base_dir of the simple-php-github-api:

cd vendor/diversen/simple-php-github-api

Configuration

cp example/config.php-dist example/config.php

Edit config

Set config in example/config.php according to above settings and the screenshot above.

Run test-server with example:

php -S localhost:8080 -t example/

More github API info

For full listing of all API calls check:

https://developer.github.com/v3/

Scope:

https://developer.github.com/v3/oauth/#scopes

I have not tested many calls - but you should be able to use all. E.g. POST, or PATCH, DELETE.

Support

Create an issue, and Let me hear if it does not work out for you.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].