Hey, guys. So I decided to work (play) around with the Scratch API and add some of my own functioning to it.
> The Site
> The Source
The styling isn't that great, as I started this today. Suggest some new features to be added.
Also, the website is kinda slow. I'm not sure why, but I think it's because I'm calling external resources multiple times upon loading. Just be patient for now.
Todo List:
Project Data - Get loves, views, and other stats. I may even try description.![]()
(Top Secret Idea: Wouldn't be cool if there was a Scratch social network using the api? The only info the actual website would have to store is maybe posts. Or maybe the feed would be of your friends posts on these forums. o: That would be a really cool expirement....)
Last edited by ProgrammingFreak (2012-08-25 15:36:23)
Offline
Looks fantastic! Works for me, but the script times out quite a lot. As for the styling, no need to change anything.
Offline
Is all it does get your friends list?
Offline
TheSuccessor wrote:
Looks fantastic! Works for me, but the script times out quite a lot. As for the styling, no need to change anything.
![]()
Thanks! I think it's because I'm calling an external page every friend.
bobbybee wrote:
Is all it does get your friends list?
For now.
I don't think you realize what takes place when it gets your friends. The Scratch API only returns the ids of your friends. I had to take the ids and dynamically change them to their actual username. And then get their images.
The code is fairly simple now, it just took me a bit to think out my strategy.
Offline
In that case, kudos to you.
Offline
Thanks.
Do you have any ideas for other features?
Offline
MathWizz wrote:
Code:
Fatal error: Maximum execution time of 10 seconds exceeded in /home/a7330029/public_html/index.php on line 38xD
Yeah, I know. >.<
I don't know why it takes so long....any suggestions?
Offline
Source:
Updated 8/25/12 - Split list into pages and made into clean url
<html>
<head>
<title>ScratchAPI++</title>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<style>
.user {
background-color:#adadad;
margin-top:5px;
margin-bottom:5px;
min-height:90px;
padding:5px;
-moz-box-shadow: inset 0 0 10px #000000;
-webkit-box-shadow: inset 0 0 10px #000000;
box-shadow: inset 0 0 10px #000000;
}
.user img {
float:left;
margin-right:10px;
}
.nav {
width:200px;
height:100px;
background-color:#adadad;
margin-top:5px;
margin-bottom:5px;
min-height:90px;
padding:5px;
-moz-box-shadow: inset 0 0 10px #000000;
-webkit-box-shadow: inset 0 0 10px #000000;
box-shadow: inset 0 0 10px #000000;
float:right;
}
.nav:first-child {
float:left;
}
body {
background-color:#515050
}
h1 {
color:#adadad;
}
p {
color:#fff;
}
</style>
</head>
<body>
<div id="container">
<?php
if(isset($_GET['user'])){
echo "<h1>" . $_GET['user'] . "'s Friends</h1>";
if(isset($_GET['id'])){
$id= $_GET['id'];
} else {
$id = '0';
}
//---------FUNCTIONS---------//
function getTitle($Url){ //Credit to http://stackoverflow.com/questions/4348912/get-title-of-website-via-link
$str = file_get_contents($Url);
if(strlen($str)>0){
preg_match("/\<title\>(.*)\<\/title\>/",$str,$title);
return $title[1];
}
}
$friends = ltrim(file_get_contents("http://scratch.mit.edu/api/getfriendsbyusername/" . $_GET['user']));
$friends = explode(":", $friends);
$num = count($friends) - 1;
for ($i = $id; $i <= $num; $i++) {
if($i < $id + 4){
$web = explode("|", getTitle("http://scratch.mit.edu/users/showfriends/" . $friends[$i]));
echo "<div class='user'><img src='http://scratch.mit.edu/static/icons/buddy/" . $friends[$i] . "_med.png' height='95px' width='95px'/><a href='http://scratch.mit.edu/users/" . $web[2] . "'>";
print_r($web[2]);
echo "</a><a href='/user/" . $web[2] . "' alt='Look at their friends'>[x]</a></div>";
} else {
echo "<div class='nav'><a href='/user/" . $_GET['user'] . "/id/" . ($id + 4) . "'>Next Page ></a></div>";
break;
}
}
if ($id > '0'){
echo "<div class='nav'><a href='/user/" . $_GET['user'] . "/id/" . ($id - 4) . "'>< Previous Page</a></div>";
} else {
echo "</div>";
}
} else {
echo "
<p>The user is not specified in the url.<br/>
To fix this problem, add this to the url:<br/>
/user/ENTER_SCRATCH_USERNAME_HERE<br/><br/>
~ProgrammingFreak</p>
";
}
?>
</div>
</body>
</html>Last edited by ProgrammingFreak (2012-08-25 15:20:25)
Offline
ProgrammingFreak wrote:
MathWizz wrote:
Code:
Fatal error: Maximum execution time of 10 seconds exceeded in /home/a7330029/public_html/index.php on line 38xD
Yeah, I know. >.<
I don't know why it takes so long....any suggestions?![]()
Maybe you should list a number of people on one page, then add next and previous page links at the top and bottom?
Offline
Perhaps that would make it be a little faster.
Thanks, Nathan.
Offline
Updated the friends feature!
Now with clean urls to make user experience a little easier. So instead of 'http://api.netai.net/index.php?user=ProgrammingFreak' its 'http://api.netai.net/user/ProgramminFreak'.
Also, at Nathan's suggestion, I added pages to the friend list. That way the loading is a lot faster!
Thanks guys!
Keep suggesting things for the friends feature and other features!
Offline