droidwiki/xenforo-bd-client

A consumer for the XenForo bd Api plugin.

0.1.1 2017-05-16 18:35 UTC

This package is not auto-updated.

Last update: 2024-12-21 21:31:12 UTC


README

This library allows to use the public api endpoint of XenForo (XenForo [bd] Api).

Usage

To authenticate an user using the OAuth2 protocol, you can use the following example. You need to create an API client at the target XenForo installation at https://example.com/account/api.

$client = new \XenForoBDClient\Clients\OAuth2Client();
$client->setBaseUrl( 'https://example.com/api/' )
	->setClientId( 'client_id' )
	->setClientSecret( 'client_secret' )
	->setRedirectUri( 'https://example2.com/redirect_target.php' )
	// see \XenForoBD\Scopes for all possible scopes
	->addScope( \XenForoBD\Scopes::READ );
if ( $_GET[ 'code' ] ) {
	$client->authenticate( $_GET['code'] );
	$user = new \XenForoBDClient\Users\User( $client );
	// will print the whole information array of the authenticated user
	var_dump($user->get( 'me' ));
} else {
	// redirect to the authentication url
	header( 'Location: ' . $client->getAuthenticationRequestUrl() );
}

To request information about an user using the user id, without needing to authenticate before doing it (e.g. using OAuth2), you can use the following example code:

$client = new \XenForoBDClient\Clients\UnauthenticatedClient();
$client->setBaseUrl( 'http://www.android-hilfe.de/api/' );
$user = new \XenForoBDClient\Users\User( $client );
// the user id in XenForo would be 102719
var_dump( $user->get( 102719 ) );