This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-08-24 15:08:39

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

[My API Site]

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.  big_smile 

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.  smile

(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

 

#2 2012-08-24 15:40:04

TheSuccessor
Scratcher
Registered: 2010-04-23
Posts: 1000+

Re: [My API Site]

Looks fantastic! Works for me, but the script times out quite a lot. As for the styling, no need to change anything.  smile


/* No comment */

Offline

 

#3 2012-08-24 15:48:54

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: [My API Site]

Is all it does get your friends list?


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#4 2012-08-24 15:58:54

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: [My API Site]

TheSuccessor wrote:

Looks fantastic! Works for me, but the script times out quite a lot. As for the styling, no need to change anything.  smile

Thanks! I think it's because I'm calling an external page every friend.  hmm

bobbybee wrote:

Is all it does get your friends list?

For now.  smile
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.  smile

Offline

 

#5 2012-08-24 16:14:05

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: [My API Site]

In that case, kudos to you.  big_smile


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#6 2012-08-24 16:30:23

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: [My API Site]

Thanks.  big_smile
Do you have any ideas for other features?

Offline

 

#7 2012-08-24 16:50:47

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: [My API Site]

Code:

Fatal error: Maximum execution time of 10 seconds exceeded in /home/a7330029/public_html/index.php on line 38

xD


http://block.site90.net/scratch.mit/text.php?size=30&text=%20A%20signature!&color=333333

Offline

 

#8 2012-08-24 16:57:15

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: [My API Site]

MathWizz wrote:

Code:

Fatal error: Maximum execution time of 10 seconds exceeded in /home/a7330029/public_html/index.php on line 38

xD

Yeah, I know. >.<
I don't know why it takes so long....any suggestions?  tongue

Offline

 

#9 2012-08-24 17:07:47

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: [My API Site]

Source:
Updated 8/25/12 - Split list into pages and made into clean url

Code:

<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

 

#10 2012-08-25 05:03:24

nathanprocks
Scratcher
Registered: 2011-04-14
Posts: 1000+

Re: [My API Site]

ProgrammingFreak wrote:

MathWizz wrote:

Code:

Fatal error: Maximum execution time of 10 seconds exceeded in /home/a7330029/public_html/index.php on line 38

xD

Yeah, I know. >.<
I don't know why it takes so long....any suggestions?  tongue

Maybe you should list a number of people on one page, then add next and previous page links at the top and bottom?


http://carrot.cassiedragonandfriends.org/Scratch_Signature/randomsig.php
http://trinary.site40.net/images/scratchrank.php?username=nathanprocks&amp;display=small

Offline

 

#11 2012-08-25 08:58:23

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: [My API Site]

Perhaps that would make it be a little faster.  big_smile
Thanks, Nathan.  smile

Offline

 

#12 2012-08-25 15:14:48

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: [My API Site]

Updated the friends feature!  big_smile
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!  big_smile  Thanks guys!

Keep suggesting things for the friends feature and other features!  big_smile

Offline

 

Board footer