The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Grabbing value from an API (existing code)
I know I'm asking a lot lately, but I'm still learning. Currently, I'm using this code (in attempts) to get the proper value: (inside a *.PHP file)
Code:
$url = sprintf("http://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key=%s&steamid=%s", $api_key, $steam_id); $curl_time = microtime(1); // Needs curl to actually be able to pull data from steam api because of the special response-behaviour. $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $url ); @curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch, CURLOPT_AUTOREFERER, true ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); curl_setopt( $ch, CURLOPT_MAXREDIRS, 5 ); curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $vbulletin->options['stc_curl_timeout'] ); #rc1: helps with page delay if steam is down $tradeban = curl_exec( $ch ); $http_response_header = curl_getinfo( $ch ); $curl_errno = curl_errno($ch); $curl_error = curl_error($ch); curl_close($ch); $tradeban = json_decode($tradeban, 1); Code:
$steam_info['EconomyBan'] = is_array($tradeban) && isset($tradeban['players'], $tradeban['players']['EconomyBan']) ? $tradeban['players']['EconomyBan'] : -1; Quote:
Quote:
Forgot to mention. EconomyBan is already filled in in the steam options plugin (see attachment), so the EconomyBan field should be called. You can ignore the rest of the text on the attachment provided below, the author already has created this steam_level check for me: Code:
$url = sprintf("http://api.steampowered.com/IPlayerService/GetSteamLevel/v0001/?key=%s&steamid=%s", $api_key, $steam_id); $curl_time = microtime(1); // Needs curl to actually be able to pull data from steam api because of the special response-behaviour. $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $url ); @curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch, CURLOPT_AUTOREFERER, true ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); curl_setopt( $ch, CURLOPT_MAXREDIRS, 5 ); curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $vbulletin->options['stc_curl_timeout'] ); #rc1: helps with page delay if steam is down $steamlevel = curl_exec( $ch ); $http_response_header = curl_getinfo( $ch ); $curl_errno = curl_errno($ch); $curl_error = curl_error($ch); curl_close($ch); $steamlevel = json_decode($steamlevel, 1); Code:
$steam_info['player_level'] = is_array($steamlevel) && isset($steamlevel['response'], $steamlevel['response']['player_level']) ? $steamlevel['response']['player_level'] : -1; |
#2
|
|||
|
|||
What do you get when you var_dump or print_r the json_decoded string?
|
#3
|
|||
|
|||
Quote:
Code:
$tradeban = json_decode($tradeban, 1); Code:
$tradeban = var_dump(json_decode($tradeban, 1)); Forgot to mention, all these changes are within a *.PHP file, rather than a plugin. Might be good to know as well where the var is being dumped. In debug mode, under messages? Tried that with above code (if thats correct), but shows no new info in debug mode -> messages. |
#4
|
||||
|
||||
That's basic PHP, it has nothing to do with vb's debug system.
See: http://php.net/manual/en/function.var-dump.php Your second code would not work. var_dump or print_r print the content of the variable or array directly to the screen. The output can't be saved to a variable. It's just PHP Code:
|
#5
|
|||
|
|||
Here's the entire PHP file just for the sake of it:
Quote:
I've created a PHP code specially designed to check 2 variables: Code:
require_once(DIR . '/includes/functions_steamconnect.php'); // Steam Level Information API $steam_id = get_user_steamid($stc_userinfo); $steam_info = fetch_steam_info($steam_id, $vbulletin->options['stc_apikey']); var_dump($steam_info['player_level']); var_dump($steam_info['tradeban']); Quote:
Using: Code:
var_dump($steam_info['EconomyBan']) [s]It 'might' be possible its giving NULL results as the results are being cached within files (for each user) that is defined in another PHP file: Quote:
^- Striped above, I've edited this post as I've posted the var_dump results on a separated plugin calling the right information. Left the edit intact, just in case. ---EDIT: Does this have something to do with it? Seeing -1 is mentioned here, as a matching value. line 184 to 200 (first pastebin) Code:
$values = $match[1]; foreach ($values AS $val) { $match = array(); preg_match("/\"(.+)\": ([^,]*),?/", $val, $match); if (is_array($match) && count($match) == 3) { $name = $match[1]; $value = trim($match[2]); if (!in_array($name, $whitelist)) continue; // Not a setting we're looking for. skip.. // Strip quotes and slashes if ($value{0} == '"' && $value{strlen($value)-1} == '"') $value = stripslashes(substr($value, 1, -1)); $steam_info[$name] = $value; } } Really would like to know why. ----SOLVED IT----- Wanted to share, got it to work with some help. First, URL near the end had to be "steamids" rather than "steamid" Second: Code:
$steam_info['EconomyBan'] = is_array($tradeban) && isset($tradeban['players'], $tradeban['players']['EconomyBan']) ? $tradeban['players']['EconomyBan'] : -1; Code:
$steam_info['EconomyBan'] = is_array($tradeban) && isset($tradeban['players'], $tradeban['players'][0]['EconomyBan']) ? $tradeban['players'][0]['EconomyBan'] : -1; |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|