PHP code example of maras0830 / laravel5-battlenet-api

1. Go to this page and download the library: Download maras0830/laravel5-battlenet-api 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/ */

    

maras0830 / laravel5-battlenet-api example snippets


{
    "id": XXXXXXXX,
    "battletag": "Maras#3218"
}

Maras0830\BattleNetApi\Providers\ApiServiceProvider::class

'BattleNetApi'             => Maras0830\BattleNetApi\Facades\ApiServiceFacade::class,

php artisan vendor:publish --force

return [
    'region' => env('Battle_net_region', 'sea'),
    'api_url' => "https://". env('Battle_net_region', 'sea') .".api.battle.net",
    'api_url_cn' => "https://api.battle.com.cn/",
    'client_id' => env('Battle_net_client_id', ''),
    'client_secret' => env('Battle_net_client_secret', ''),
    'redirect_url' => env('APP_URL'). '/' .env('Battle_net_redirect_url', '') . '/battleNet/callback',
    'scopes' => [
        'wow.profile',
        'sc2.profile'
    ]
];

Route::get('battleNet', 'auth\social\AuthController@redirectToProvider_BattleNet');
Route::get('battleNet/callback', 'auth\social\AuthController@handleProviderCallback_BattleNet');

public function redirectToProvider_BattleNet()
{
    return redirect(BattleNetApi::authenticationURL()); // redirect to BattleNet login page
}

public function handleProviderCallback_BattleNet()
{
    $social_type = "BattleNet";

    if (isset($_GET['code'])) {
        $code = $_GET['code'];

        $token = BattleNetApi::requestToken($code);

        $account = BattleNetApi::authenticatedUser($token);
    } else
        return redirect('/')->withErrors('failed.');

}