droidwiki/xenforo-bd-client

是 XenForo bd Api 插件的一个消费者。

0.1.1 2017-05-16 18:35 UTC

This package is not auto-updated.

Last update: 2024-09-28 20:20:01 UTC


README

此库允许使用 XenForo 的公开 API 端点(XenForo [bd] Api)。

用法

要使用 OAuth2 协议认证用户,可以使用以下示例。您需要在目标 XenForo 安装中创建一个 API 客户端,地址为 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() );
}

要使用用户 ID 请求关于用户的信息,而无需在执行操作前进行认证(例如使用 OAuth2),可以使用以下示例代码

$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 ) );