Skip to content
TORNLIFE More

Just a simple question

Started by Detective [1557351] on in API Development.

5 replies · 91 views · thread synced · 5 days ago · View on torn.com
About this thread

Posts archived: 6 / 6 posts (100%) · the total is Torn's reply count + the opening post at the last fetch

Counted by TornLife from the archived posts.

Archived posts
6
Discussion span
→
People posting
3
Likes on archived posts
1
Authority score
51 / 100
Historical score
17 / 100
Story score
25 / 100
Engagement score
44 / 100
Detective [1557351]

Does API/site have a direct link to users profile in jason format?

Because, lets say I want to list 20 users and check theirs last actions. "file_get_contents($variable);" takes forever to parse.
Mauk [1494436]

I have no idea what you mean. You can always create a link to a profile given its ID: `https://www.torn.com/profiles.php?XID=${ID}`.

That's probably not what you're talking about, but I'm lost here.
Jeggy [1526723]

if you have a list of 20 users, you just loop them and use the User api like this:
https://api.torn.com/user/1557351?selections=profile&key={APIKEY}

but as you ain't the owner of the user, you won't have access to all their data. fields that can be viewed on other users are:
  • bazaar
  • display
  • icons
  • profile
  • basic
You can play more with on
https://api.torn.com/

Here's a PHP example using the httpful library ;)

<?php
include('./httpful.phar');

$apiKey = "Key";
$users = [1557351,1494436,1526723];

$data = "";
foreach($users as $id){
$res = Request::get("https://api.torn.com/user/$id?selections=profile&key=$apiKey")->send();
echo "name: ".$res->body->name."<br />";
echo "last_action:".$res->body->last_action."<br />";
}

Detective [1557351]
[image: i.imgur.com]
$enemy is not declared here, but it's array consisting user Id's. there's part missing on the right since prntscrn couldn't cover it. This is working fine, but problem is that it gets super slow on the $jsonuser = file_get_contents($userlink); line.

Is there any way to get that working faster?

This is just for fun, I have course on university about dynamic web applications where we're learning PHP at moment, so I thought it would be nice exercise to do something with torn api.
Mauk [1494436]

I see.

I'm willing to bet `file_get_contents` waits until the TCP connection is closed, but Torn's server are probably assuming a `Keep-Alive` header as PHP won't send any by default, so they keep the connection open for a while.

Try using:

$options = array('http' => array('header' => 'Connection: close'));
$context = stream_context_create($options);
file_get_contents("https://api.torn.com/user/{$ids[$j]}?&key=9TYYnPwE", false, $context);

If that doesn't help, switch from `file_get_contents` to something else like cURL or an http client library.