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.
Sample output:
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:
Then you can simply put $aviname into some echoed html like so:
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:
More information on the decode function: http://php.net/manual/en/function.json-decode.php
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.
$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:
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:
Then you can simply put $aviname into some echoed html like so:
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