Skip to content
Advertisement

Roblox API ( Avatar Equipment )

I am currently working on Roblox API. I am stuck on one question. Reason : I have this link https://avatar.roblox.com/v1/users/2/currently-wearing. This shows what specified users have equipped on them. this link right here shows this: {“assetIds”:[382537569,607702162,607785314]} My goal is to get the assetIds to string. I tried this:

<?php
$id = 2;
$ch = file_get_contents("https://avatar.roblox.com/v1/users/$id/currently-wearing");
$ch = curl_init($ch);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$data = curl_exec($ch);

$data = json_decode($data);

$id = "$data->assetIds";
echo $id;

But it Shows Array. I need some help.

Advertisement

Answer

The cURL is not necessary as the file_get_contents() get you the data you appear to require

$id = 2;
$ch = file_get_contents("https://avatar.roblox.com/v1/users/2/currently-wearing");

$data = json_decode($ch);

foreach ($data->assetIds as $id){
    echo $id . PHP_EOL;
}

RESULT

382537569
607702162
607785314
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement