Parsing json Data

DataMine
by DataMine · 10 posts
11 years ago in PHP
Posted 11 years ago · Author
This simple PhP code will allow you to take the contents of json data from IMVU and print it out for viewing and then parsing. This is what it used in the unfinished avicard generator I am making for our site. You can find it here: https://www.imvumafias.org/imvu/Tools.html


This code will grab the contents of the api and use the json_decode function to convert it into a format we can easily use.
Code
$cardurl = "http://client-dynamic.imvu.com/api/avatarcard.php?cid=$cid&viewer_cid=$cid";
      
$avicardcode = @file_get_contents($cardurl);
      
$jsondata = $avicardcode;   
$obj = json_decode($jsondata);
      
echo "<pre>"; var_dump($obj); echo "</pre>";


Sample output:
Code
object(stdClass)#1 (31) {
  ["viewer_cid"]=>
  int(39506145)
  ["cid"]=>
  int(39506145)
  ["is_buddy"]=>
  bool(false)
  ["is_friend"]=>
  bool(false)
  ["is_qa"]=>
  bool(false)
  ["avname"]=>
  string(4) "Carl"
  ["url"]=>
  string(28) "http://avatars.imvu.com/Carl"
  ["avpic_url"]=>
  string(114) "http://userimages-akm.imvu.com/catalog/includes/modules/phpbb2/images/avatars/39506145_105188422650bb89f365928.png"
  ["registered"]=>
  string(10) "2009-07-23"
  ["last_login"]=>
  string(8) "01/07/13"
  ["interests"]=>
  object(stdClass)#2 (1) {
    ["full_text_string"]=>
    object(stdClass)#3 (2) {
      ["tag"]=>
      string(0) ""
      ["raw_tag"]=>
      string(0) ""
    }
  }
  ["dating"]=>
  object(stdClass)#4 (3) {
    ["relationship_status"]=>
    string(17) "Prefer Not To Say"
    ["orientation"]=>
    string(17) "Prefer Not To Say"
    ["looking_for"]=>
    string(17) "Prefer Not To Say"
  }
  ["gender"]=>
  string(4) "Male"
  ["age"]=>
  string(2) "NA"
  ["tagline"]=>
  string(27) "Don't over think it, DO IT!"
  ["location"]=>
  string(44) "United Kingdom"
  ["country_code"]=>
  int(222)
  ["location_state"]=>
  NULL
  ["badge_count"]=>
  int(6)
  ["badge_level"]=>
  int(1)
  ["online"]=>
  bool(false)
  ["availability"]=>
  string(9) "Available"
  ["badge_layout"]=>
  object(stdClass)#5 (1) {
    ["badge-29159055-1"]=>
    object(stdClass)#6 (16) {
      ["creator_id"]=>
      int(29159055)
      ["creator_badge_index"]=>
      int(1)
      ["name"]=>
      string(11) "Sublimiinal"
      ["image_mogilekey"]=>
      string(61) "/userdata/29159055/badge_90b6838315b27691a7180668565020fa.gif"
      ["image_width"]=>
      int(20)
      ["image_height"]=>
      int(20)
      ["description"]=>
      string(220) "
ConfessionCoutureBanner-2.jpg
"
      ["allow_autogrant"]=>
      string(1) "1"
      ["review_status"]=>
      string(13) "passed_review"
      ["flagger_id"]=>
      string(1) "0"
      ["flag_time"]=>
      string(19) "0000-00-00 00:00:00"
      ["badgeid"]=>
      string(16) "badge-29159055-1"
      ["image_url"]=>
      string(89) "http://userimages01.imvu.com/userdata/29159055/badge_90b6838315b27691a7180668565020fa.gif"
      ["json_desc"]=>
      string(243) ""
\"ConfessionCoutureBanner-2.jpg\"\/<\/a><\/center>"" ["xloc"]=> int(0) ["yloc"]=> int(0) } } ["badge_area_html"]=> string(230) "Sublimiinal" ["show_flag_icon"]=> int(0) ["show_flag_av"]=> int(1) ["avpic_default"]=> int(0) ["show_block"]=> bool(false) ["is_creator"]=> int(1) ["public_rooms"]=> array(0) { } ["visible_albums"]=> int(1) }


Now you may be wondering how you use this? Simple. Say you want to get the avi name so you can echo it into some html. Then you need to do this:
Code
$aviname = $obj->avname;


Then you can simply put $aviname into some echoed html like so:
Code
echo"<h1>$aviname</h1>"


And now the avi name will be displayed in the h1 tags like this:
Carl

Now as you can probably guess, this makes it easy to make generators and things that are gonna have different output.

Here is a list of pre made variables that work with the code above:
    $aviname = $obj->avname;
    $avpic = $obj->avpic_url;
    $hplink = $obj->url;
    $registered = $obj->registered;
    $lastonline = $obj->last_login;
    $gender = $obj->gender;
    $age = $obj->age;
    $flag = $obj->country_code;
    $country = $obj->location;
    $albums = $obj->visible_albums;
    $tagline = $obj->tagline;
    $availability = $obj->availability;
    $badgenum = $obj->badge_count;
    $ap = $obj->show_ap;
    $vip = $obj->show_vip;
    $creator = $obj->is_creator;
    $online = $obj->online;
    $friend = $obj->is_friend;
    $relationship = $obj->dating->relationship_status;
    $orientation = $obj->dating->orientation;
    $herefor = $obj->dating->looking_for;
    $interests = $obj->interests->full_text_string->raw_tag;


More information on the decode function: http://php.net/manual/en/function.json-decode.php
Posted 11 years ago
Notice IMVU changed this partly you need to be logged in to access most of the info now
Posted 11 years ago · Author
Ťṓƴᶎ wrote:
Notice IMVU changed this partly you need to be logged in to access most of the info now


It's been about a week since I last used any of this code but I found that when you supply a viewer cid to the parameters, it bypasses the need for logging in.
Posted 10 years ago
D.M wrote:
It's been about a week since I last used any of this code but I found that when you supply a viewer cid to the parameters, it bypasses the need for logging in.

My, the security guys at IMVU sure know how it's done ;)

Have you checked if supplying the cid of an AP enabled member is enough to access AP restricted pages by script? Then we wouldn't have to do the effort of logging in via curl.
Posted 10 years ago · Author
little_tramp wrote:
D.M wrote:
It's been about a week since I last used any of this code but I found that when you supply a viewer cid to the parameters, it bypasses the need for logging in.

My, the security guys at IMVU sure know how it's done ;)

Have you checked if supplying the cid of an AP enabled member is enough to access AP restricted pages by script? Then we wouldn't have to do the effort of logging in via curl.


I do not remember if I have tried that. But I will keep it in mind and try it.
Posted 10 years ago
little_tramp wrote:
D.M wrote:
It's been about a week since I last used any of this code but I found that when you supply a viewer cid to the parameters, it bypasses the need for logging in.

My, the security guys at IMVU sure know how it's done ;)

Have you checked if supplying the cid of an AP enabled member is enough to access AP restricted pages by script? Then we wouldn't have to do the effort of logging in via curl.
'

That is a great idea! Interests and taglines have all the dirty words covered up with asterisks if you do not have AP. It can be a real pain to see what some people are saying in their tagline if you do not have AP.
Posted 9 years ago
I allow myself to dig about it, I do not really know if I just ask this here or in the section vb .net but we can do this kind of thing with vb. net and if so, an idea of ​​how to do?

(sorry for my english , I'm french and I use google translate)
Posted 9 years ago · Author
kyushyrax wrote:
I allow myself to dig about it, I do not really know if I just ask this here or in the section vb .net but we can do this kind of thing with vb. net and if so, an idea of ​​how to do?
(sorry for my english , I'm french and I use google translate)


Yeah, you can. You just use the json.net library. I do this in c# all the time for a lot of my programs. http://james.newtonking.com/json
Posted 9 years ago
thank you :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Sign in

Already have an account? Sign in here

SIGN IN NOW

Create an account

Sign up for a new account in our community. It's easy!

REGISTER A NEW ACCOUNT