HowTo: Use the WebApi [PHP]

91 views
Skip to first unread message

Bilal Raja

unread,
May 3, 2017, 3:36:01 PM5/3/17
to Steam Condenser
As this library is very poorly documented, I am trying to understand it's usage and will use it if it's fairly easy and useful...

I think it would be alright to ask how can I get the WebApi feature to use...
and also what is the best full basic script from which I can understand this library enough to use it...

I have made this script, but it gives me errors

Script:
<?php

require "lib\steam-condenser.php";
require_once 'lib\steam\community\WebApi.php';

$WEBAPI = WebApi::setApiKey("SECRET");
$WEBAPI2 = WebApi::getApiKey();

print $WEBAPI2;


$params = array('appid' => 4000, 'count' => 5,'maxlength' => null);

$data = WebApi::getJSONData('ISteamNews', 'GetNewsForApp', 2, $params);
//$data = WebApi::getInterfaces();

print_r($data);
/*
$id = SteamId::create('demomenz');
$stats = $id->getGameStats('tf2');
$achievements = $stats->getAchievements();
$achievements1 = $achievements->GameAchievement;

print_r($achievements1);
*/
?>

Error:
SECRET
Notice: Querying Steam Web API: https://api.steampowered.com/ISteamNews/GetNewsForApp/v0002/?appid=4000&count=5&maxlength=&format=json&key=SECRET in E:\XAMPP\htdocs\TEMP_TESTS\lib\steam\community\WebApi.php on line 238

Notice: Undefined property: stdClass::$result in E:\XAMPP\htdocs\TEMP_TESTS\lib\steam\community\WebApi.php on line 184

Notice: Trying to get property of non-object in E:\XAMPP\htdocs\TEMP_TESTS\lib\steam\community\WebApi.php on line 186

Notice: Trying to get property of non-object in E:\XAMPP\htdocs\TEMP_TESTS\lib\steam\community\WebApi.php on line 187

Notice: Trying to get property of non-object in E:\XAMPP\htdocs\TEMP_TESTS\lib\steam\community\WebApi.php on line 187

Fatal error: Uncaught WebApiException: The Web API request failed with the following error: (status code: ). in E:\XAMPP\htdocs\TEMP_TESTS\lib\steam\community\WebApi.php:187 Stack trace: #0 E:\XAMPP\htdocs\TEMP_TESTS\lib\steam\community\WebApi.php(89): WebApi->_getJSONData('ISteamNews', 'GetNewsForApp', 2, Array) #1 E:\XAMPP\htdocs\TEMP_TESTS\index.php(14): WebApi::getJSONData('ISteamNews', 'GetNewsForApp', 2, Array) #2 {main} thrown in E:\XAMPP\htdocs\TEMP_TESTS\lib\steam\community\WebApi.php on line 187


Sebastian Staudt

unread,
May 5, 2017, 7:03:11 AM5/5/17
to Steam Condenser
Hi,

you're using the wrong method as ISteamNews/GetNewsForApp does not follow the Web API's "standard" format.
What you want is probably this:

$data = json_decode(WebApi::getJSON('ISteamNews', 'GetNewsForApp', 2, $params));

That way you'll have a decoded object from the JSON data returned by the API, but without any checks that getJSONData() does for you.

Even better, there's AppNews::getNewsForApp() which already brings additional logic to get "real" objects.

Best regards,
    Sebastian

--
You received this message because you are subscribed to the Google Groups "Steam Condenser" group.
To unsubscribe from this group and stop receiving emails from it, send an email to steam-condens...@googlegroups.com.
To post to this group, send email to steam-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/steam-condenser/207a6e99-06f2-41bc-9dce-cb8fe507f740%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages