Blizzard Api OAuth in php

API Discussion
my api lib still functions, 400 refers to malformed request what part in the script does the lib fail or is it failing all together?
Wanting to let you know, if $region is lowercase, nothing will happen (malformed url error thrown).

Also, apparently within account.php in /ext/, the starting slash of for example:

case 'user':
$q = '/account/user';
break;


will result in a malformed URL as well:

https://REGION.api.battle.net//account/user?source=account&apikey=KEY&access_token=TOKEN&locale=en_US


Removing the / fixed it for me.
lib could be a lil outdated for the new urls dropping ial review and add some changes in the next few days
Hi Ulminia,

is there any chance that you migrate your perfect script for the new api?
I tried to migrate myself by changing old urls to new ones, but it didn't work. Can I hope that there's gonna be new version of lib any time soon?
soon been working on it the past few days once its ready ial release it on github
For folks stumbling upon this as I did having issues with this library (which is an awesome way to cut your teeth getting into the Oauth2 Battle.Net API by the way), I have made a few code adjustments that got me up and running.

In the Client.php around line 154 you'll see:
public $baseurl = array(

'US' => array(


In here I made two changes. First, the API path should be changed to reflect the new API path. Changed from:
'urlbase' => 'https://us.api.battle.net/',

to:
'urlbase' => 'https://us.api.blizzard.com/',

And then I added a new key to the array for use during the fetch function (you can add it anywhere in the array, I put mine just under the urlbase key mentioned above):

'accountbase' => 'https://us.battle.net/oauth',

This part was a total hack for MY needs but I use the new accountbase key in the _buildUrl function where I added a condition to check if the 'source' is account and the 'path' is userinfo. So where it reads:

if ( isset($params['source']) )
{
$url .= $this->ext->_buildtype($path,$params);//$protected_resource_url = $ext->_buildUrl($protected_resource_url, $parameters);
}
else


I added a condition:
{
if ($params['source'] == 'account' && $path == 'userinfo') {
$url = $this->baseurl[$this->region]['accountbase'] . '/userinfo';
}
$url .= $this->ext->_buildtype($path,$params);//$protected_resource_url = $ext->_buildUrl($protected_resource_url, $parameters);
}


This was so I could call up the user account information like this (this is just a modified version of the included index.php):

$client->setAccessToken($response['result']['access_token']);
$response = $client->fetch('userinfo',array('source'=>'account'));


And now all functions work, including a new one to fetch the user info.

I hacked that last part because I only really wanted to muck with the Client.php and not change anything in the ext/account.php (although I likely will add a few more functions to the wow.php).

I suppose I could fork the distro but it's only a couple of easy changes to go from 400 errors to fully working and being able to capitalize on Ulminia's great work!

Thanks Ulminia for making this library so accessible and so easy to work with :).
your welcome the new code is in the final stages just need to test all end points and make sure data is returned the same way
Hi Uliminia,
i have my values in the index.php for
$ client_id = 'xxxxxxx';
$ client_secret = 'yyyyyyyyyy';
$ region = 'EU';
$ locale = 'de_DE';
$ redirect_uri = 'https://www.axolotl.saarland/wow_test/test.php';

set. When I run the index.php I get the following error:

Fatal error: Class 'OAuth \ InvalidArgumentException' not found in /mnt/web209/e1/99/53909799/htdocs/home/markus-home/wow_test/Client.php on line 314

What am I doing wrong, I have never had anything to do with Oauth.

greeting
Markus
Markus,

How are you calling the library after you init those variables? And I presume there really isn't a space between your $ and the variable name as you posted :). Once you define those variables you need to have the callback to your script to process the code:


$client = new OAuth2\Client($client_id, $client_secret, $region, $locale, $redirect_uri);
$auth_url = $client->getAuthenticationUrl($client->baseurl[$client->region]['AUTHORIZATION_ENDPOINT'], $client->redirect_uri, array('state' => ''));


Which will then call the script back with a code that you then process:


$params = array('code' => $_GET['code'], 'auth_flow' => 'auth_code', 'redirect_uri' => $client->redirect_uri);
$auth = $client->getAccessToken($client->baseurl[$client->region]['TOKEN_ENDPOINT'], 'authorization_code', $params);


So that you can use that token to make a call. Now this is all assuming you want the protected call to get the Oauth data rather than just make generic calls to the API (i.e., getting guild members, achievements, etc). The Oauth callback method is only needed if you are doing things like getting the battletag of the player or the list of characters on the account.

Disclaimer: This is how I implement this library successfully, so much depends on what you are trying to do and of course you only posted a snippet of code that defines variables, not actually calls the library or processes the data returned on the callback.
Hey!
I think Barail is referring to Ulminia's latest update, which includes the new developer portal and URLs:
https://github.com/Ulminia/blizzard-api-oauth

I am running into the same problem with it, with simply following the guide and initializing the client:
$client = new OAuth\oauthApi($client_id, $client_secret, $region, $locale, $redirect_uri);

Looking at the Client.php I would assume it has something to do with the access token requirement mentioned in the documentation, but what the reason exactly is or how to work with it correctly is sadly beyond me.
Quick update: The Client.php needs 2 quick changes:

comment out line 24:
// namespace OAuth;

removed the namespace in line 312 so it reads:
$grantTypeClass = $grantTypeClassName;

This should make it work. Ulminia also added a more detailed flow on how to use the script: https://github.com/Ulminia/blizzard-api-oauth/wiki/User-login-code

Join the Conversation

Return to Forum