1. Go to this page and download the library: Download oneduo/github-sdk-php 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/ */
oneduo / github-sdk-php example snippets
use Oneduo\GitHubSdk\GitHubConnector;
$github = new GitHubConnector();
use Saloon\Http\Auth\TokenAuthenticator;
$github = new GitHubConnector();
$github->authenticate(new TokenAuthenticator('your-github-token'));
// Now you can access authenticated endpoints
$response = $github->users()->getAuthenticated();
$user = $response->json();
use Saloon\Http\Auth\BasicAuthenticator;
$github = new GitHubConnector();
$github->authenticate(new BasicAuthenticator('your-username', 'your-password'));
// Now you can access authenticated endpoints
$response = $github->users()->getAuthenticated();
$user = $response->json();
use Oneduo\GitHubSdk\Authenticators\AppAuthenticator;
// Using a private key file path
$github = new GitHubConnector();
$github->authenticate(new AppAuthenticator(
appId: 'your-app-id',
key: '/path/to/your/private-key.pem'
));
// Or using key content directly
$github = new GitHubConnector();
$github->authenticate(new AppAuthenticator(
appId: 'your-app-id',
key: '-----BEGIN RSA PRIVATE KEY-----...'
));
// With passphrase if your key is encrypted
$github = new GitHubConnector();
$github->authenticate(new AppAuthenticator(
appId: 'your-app-id',
key: '/path/to/your/private-key.pem',
passphrase: 'your-passphrase'
));
// Using an existing OpenSSLAsymmetricKey resource (PHP 8.0+)
$keyResource = openssl_pkey_get_private(file_get_contents('/path/to/key.pem'));
$github = new GitHubConnector();
$github->authenticate(new AppAuthenticator(
appId: 'your-app-id',
key: $keyResource
));
// Now you can access GitHub App endpoints
$response = $github->apps()->getAuthenticated();
$app = $response->json();