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

#1 2012-02-20 15:05:21

cocolover76
Scratcher
Registered: 2011-10-09
Posts: 500+

How do you use the API?

Specifically for web applications.
AJAX can't access a different server to get the value.
So what JS file do I embed to use the API for web applications?


http://i.imgur.com/HfEPZ.gifhttp://i.imgur.com/pvKb6.png

Offline

 

#2 2012-02-20 15:28:37

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: How do you use the API?

cocolover76 wrote:

Specifically for web applications.
AJAX can't access a different server to get the value.
So what JS file do I embed to use the API for web applications?

PHP can fetch values using file_get_contents('http://') etc.

For JS, AJAX can get data from other servers, can't it?

Offline

 

#3 2012-02-20 15:31:09

cocolover76
Scratcher
Registered: 2011-10-09
Posts: 500+

Re: How do you use the API?

LS97 wrote:

cocolover76 wrote:

Specifically for web applications.
AJAX can't access a different server to get the value.
So what JS file do I embed to use the API for web applications?

PHP can fetch values using file_get_contents('http://') etc.

For JS, AJAX can get data from other servers, can't it?

No, AJAX can't. I tried that once to use a Dropbox HTML page to display HTML from TXT files on my Sharkserve to avoid ads AND Dropbox limits. And also, what is the URL???

Last edited by cocolover76 (2012-02-20 15:31:28)


http://i.imgur.com/HfEPZ.gifhttp://i.imgur.com/pvKb6.png

Offline

 

#4 2012-02-20 15:39:21

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: How do you use the API?

cocolover76 wrote:

LS97 wrote:

cocolover76 wrote:

Specifically for web applications.
AJAX can't access a different server to get the value.
So what JS file do I embed to use the API for web applications?

PHP can fetch values using file_get_contents('http://') etc.

For JS, AJAX can get data from other servers, can't it?

No, AJAX can't. I tried that once to use a Dropbox HTML page to display HTML from TXT files on my Sharkserve to avoid ads AND Dropbox limits. And also, what is the URL???

did you try http://www.ajax-cross-domain.com/? It sounds good.
The URL depends on the data you want...

Offline

 

#5 2012-02-20 15:57:22

cocolover76
Scratcher
Registered: 2011-10-09
Posts: 500+

Re: How do you use the API?

LS97 wrote:

cocolover76 wrote:

LS97 wrote:


PHP can fetch values using file_get_contents('http://') etc.

For JS, AJAX can get data from other servers, can't it?

No, AJAX can't. I tried that once to use a Dropbox HTML page to display HTML from TXT files on my Sharkserve to avoid ads AND Dropbox limits. And also, what is the URL???

did you try http://www.ajax-cross-domain.com/? It sounds good.
The URL depends on the data you want...

I'm looking for particularly the auth one, but is there like a list of all of the APIs?


http://i.imgur.com/HfEPZ.gifhttp://i.imgur.com/pvKb6.png

Offline

 

#6 2012-02-20 16:08:09

veggieman001
Scratcher
Registered: 2010-02-20
Posts: 1000+

Re: How do you use the API?

cocolover76 wrote:

LS97 wrote:

cocolover76 wrote:


No, AJAX can't. I tried that once to use a Dropbox HTML page to display HTML from TXT files on my Sharkserve to avoid ads AND Dropbox limits. And also, what is the URL???

did you try http://www.ajax-cross-domain.com/? It sounds good.
The URL depends on the data you want...

I'm looking for particularly the auth one, but is there like a list of all of the APIs?

Sci is working on that ^^


Posts: 20000 - Show all posts

Offline

 

#7 2012-02-20 16:12:37

cocolover76
Scratcher
Registered: 2011-10-09
Posts: 500+

Re: How do you use the API?

veggieman001 wrote:

cocolover76 wrote:

LS97 wrote:


did you try http://www.ajax-cross-domain.com/? It sounds good.
The URL depends on the data you want...

I'm looking for particularly the auth one, but is there like a list of all of the APIs?

Sci is working on that ^^

Where is the work in progress?
(PDF, Word, HTML, or Text, or I won't accept)


http://i.imgur.com/HfEPZ.gifhttp://i.imgur.com/pvKb6.png

Offline

 

#8 2012-02-20 16:41:39

cocolover76
Scratcher
Registered: 2011-10-09
Posts: 500+

Re: How do you use the API?

bump


http://i.imgur.com/HfEPZ.gifhttp://i.imgur.com/pvKb6.png

Offline

 

#9 2012-02-20 16:42:40

cocolover76
Scratcher
Registered: 2011-10-09
Posts: 500+

Re: How do you use the API?

bump


http://i.imgur.com/HfEPZ.gifhttp://i.imgur.com/pvKb6.png

Offline

 

#10 2012-02-20 16:42:57

veggieman001
Scratcher
Registered: 2010-02-20
Posts: 1000+

Re: How do you use the API?

cocolover76 wrote:

veggieman001 wrote:

cocolover76 wrote:


I'm looking for particularly the auth one, but is there like a list of all of the APIs?

Sci is working on that ^^

Where is the work in progress?
(PDF, Word, HTML, or Text, or I won't accept)

He hasn't finished it yet and hasn't released a work in progress. Jeez, be patient.


Posts: 20000 - Show all posts

Offline

 

#11 2012-02-20 16:47:34

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: How do you use the API?

There's a page on SVN that documents it though... I didn't bookmark it so I can't find it for you sorry  tongue

Offline

 

#12 2012-02-20 16:58:01

veggieman001
Scratcher
Registered: 2010-02-20
Posts: 1000+

Re: How do you use the API?

LS97 wrote:

There's a page on SVN that documents it though... I didn't bookmark it so I can't find it for you sorry  tongue

Oh... this?


Posts: 20000 - Show all posts

Offline

 

#13 2012-02-20 17:33:14

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: How do you use the API?

I believe cross-platform AJAX requires connection permissions at both ends. In which case I doubt the Scratch team would allow it.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#14 2012-02-20 18:54:40

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: How do you use the API?

cocolover76 wrote:

LS97 wrote:

cocolover76 wrote:

No, AJAX can't. I tried that once to use a Dropbox HTML page to display HTML from TXT files on my Sharkserve to avoid ads AND Dropbox limits. And also, what is the URL???

did you try http://www.ajax-cross-domain.com/? It sounds good.
The URL depends on the data you want...

I'm looking for particularly the auth one, but is there like a list of all of the APIs?

The actual source file veggieman001 posted is the best source, but I went through and deleted all the code a while ago, leaving the comments and signatures intact. It may be outdated now, but if you want you can see it here.


nXIII

Offline

 

#15 2012-02-21 00:15:25

GP1
Scratcher
Registered: 2009-07-06
Posts: 1000+

Re: How do you use the API?

Actually, you can use regular AJAX with a different server. It won't work in userscript, and you have to write your own functions. I wouldn't recomend it, though, because the browser asks the client if they want to allow the connection, so I would use php to get the info.


I am currently http://blocks.scratchr.org/API.php?user=GP1&action=onlineStatus&type=imagehttp://blocks.scratchr.org/API.php?user=GP1&action=onlineStatus&type=text and I finally got over 1000 posts.

Offline

 

#16 2012-02-21 07:37:07

SJRCS_011
Scratcher
Registered: 2011-02-07
Posts: 1000+

Re: How do you use the API?

GP1 wrote:

Actually, you can use regular AJAX with a different server. It won't work in userscript, and you have to write your own functions. I wouldn't recomend it, though, because the browser asks the client if they want to allow the connection, so I would use php to get the info.

How about the php gets the data and you use Ajax to get the data from the PHP?


http://i.imgur.com/vQqtH.png
Learning to Program in a Nutshell:  "You're missing a closing parentheses" - LS97

Offline

 

#17 2012-02-21 07:43:57

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: How do you use the API?

SJRCS_011 wrote:

GP1 wrote:

Actually, you can use regular AJAX with a different server. It won't work in userscript, and you have to write your own functions. I wouldn't recomend it, though, because the browser asks the client if they want to allow the connection, so I would use php to get the info.

How about the php gets the data and you use Ajax to get the data from the PHP?

Yes, that works, and it's exactly what I'd thought of in the first place  tongue

Offline

 

#18 2012-02-21 08:01:11

fanofcena
Scratcher
Registered: 2008-07-03
Posts: 1000+

Re: How do you use the API?

cocolover76 wrote:

Specifically for web applications.
AJAX can't access a different server to get the value.
So what JS file do I embed to use the API for web applications?

Woot ? It cant ???..

HTTP access control from x-domain

since in earlier days of web XHR was starting to go used to do a lot of illegal fetching of data from sites so w3c specified a new header for XHR which must be sent via server side
in order to allow MODERN browsers to fetch AJAX


an API must have this

Code:

Access-Control-Allow-Origin: <origin> | *

In order to allow cross domain ajax so maybe the API you are using is an internal api and not for public use..

Okay here is your workaround for fetching information and writing a PHP proxy

Code:

<?php
$base = 'http://scratch.mit.edu';
function failOut($http, $text) {
    header('HTTP/1.x ' . $http);
    die(htmlspecialchars($text));
}

$context = stream_context_create(
    array(
        'http' => array(
            // this should not be required, grrrr!
            'user_agent' => "GET / HTTP/1.0\r\n"
                        ."Host:117.200.149.48\r\n" // Replace with server IP 
                        ."User-Agent: Mozilla/5.0 (compatible; ShoutCastInfoClass/0.0.2; ".PHP_OS.")\r\n"
                        ."\r\n",
        ),
    )
);
$content = file_get_contents($base, false, $context)or die("UnABLE TO lOaD");
echo $content;

?>

The stream context is required since new web servers wont detect it as an HTTP request unless you send the proper headers and so if u just post a request like that
you probably will fall with nothing output



oh and as a tip to all javascripters

Google Chrome Console and Mozzilla Firefox Firebug are two of your best friends learn them they basically show you errors and etc when your code is wrong or when you use a method that has been deprecated ^^ ,

Last edited by fanofcena (2012-02-21 08:10:48)


http://i53.tinypic.com/2vxr2c0.png Click whats above u might make a cute planet happy ^_^

Offline

 

#19 2012-02-22 03:48:48

fanofcena
Scratcher
Registered: 2008-07-03
Posts: 1000+

Re: How do you use the API?

do i always kill the topics ?


http://i53.tinypic.com/2vxr2c0.png Click whats above u might make a cute planet happy ^_^

Offline

 

#20 2012-02-22 09:29:24

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: How do you use the API?

fanofcena wrote:

do i always kill the topics ?

Maybe because you answer them so well.  tongue

Offline

 

Board footer