Bitcoin Forum
May 09, 2024, 05:53:49 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Help with Javascript and Github Pages  (Read 1733 times)
RGBKey (OP)
Hero Member
*****
Offline Offline

Activity: 854
Merit: 658


rgbkey.github.io/pgp.txt


View Profile WWW
March 09, 2014, 01:57:51 AM
 #1

Hello, I was trying to make a site that would display API data from multiple exchanges and display it to the user as a learning project but when I went to actually use javascript to get the API data, my IP was blocked from Bitstamp's servers. I assume this is because someone on github pages went over the request limit and got the IP banned. Is there a way to make the javascript send the request from the client IP instead of the server so that the IP isn't blocked? Thanks!
1715234029
Hero Member
*
Offline Offline

Posts: 1715234029

View Profile Personal Message (Offline)

Ignore
1715234029
Reply with quote  #2

1715234029
Report to moderator
1715234029
Hero Member
*
Offline Offline

Posts: 1715234029

View Profile Personal Message (Offline)

Ignore
1715234029
Reply with quote  #2

1715234029
Report to moderator
The forum was founded in 2009 by Satoshi and Sirius. It replaced a SourceForge forum.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715234029
Hero Member
*
Offline Offline

Posts: 1715234029

View Profile Personal Message (Offline)

Ignore
1715234029
Reply with quote  #2

1715234029
Report to moderator
1715234029
Hero Member
*
Offline Offline

Posts: 1715234029

View Profile Personal Message (Offline)

Ignore
1715234029
Reply with quote  #2

1715234029
Report to moderator
1715234029
Hero Member
*
Offline Offline

Posts: 1715234029

View Profile Personal Message (Offline)

Ignore
1715234029
Reply with quote  #2

1715234029
Report to moderator
9inety7even
Member
**
Offline Offline

Activity: 84
Merit: 10


View Profile
March 09, 2014, 02:41:37 AM
 #2

If you're using something like jQuery.get() then it's already sending it from the client IP.

scribe
Sr. Member
****
Offline Offline

Activity: 295
Merit: 250



View Profile WWW
March 09, 2014, 08:20:52 AM
 #3

Are you authenticating with the bitstamp API properly? Not used it myself but the doc page says all requests need to be authenticated.  Or are you seeing a message specifically relating to limits?

blocknois.es Bitcoin music label. ~ New release: This Is Art

Read: Bitcoin Life | Wear: FUTUREECONOMY
RGBKey (OP)
Hero Member
*****
Offline Offline

Activity: 854
Merit: 658


rgbkey.github.io/pgp.txt


View Profile WWW
March 09, 2014, 11:10:09 PM
 #4

Are you authenticating with the bitstamp API properly? Not used it myself but the doc page says all requests need to be authenticated.  Or are you seeing a message specifically relating to limits?
I'm using the public part (https://www.bitstamp.net/api/ticker/) so it doesn't need authed per the docs. On my webpage with jQuery, I opened the console and did this:
Code:
var test = jQuery.getJSON("https://www.bitstamp.net/api/ticker/");
And got the error
Code:
XMLHttpRequest cannot load https://www.bitstamp.net/api/ticker/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://rgbkey.github.io' is therefore not allowed access.

I would appreciate if anyone could tell me why this doesn't work. I can load the page fine from my web browser.
9inety7even
Member
**
Offline Offline

Activity: 84
Merit: 10


View Profile
March 09, 2014, 11:49:04 PM
 #5

Like the error says, you're trying to make a cross-domain request, which it looks like bitstamp doesn't allow. You have a few options here, but I think the best one would just be to proxy the request through your servers. You can find some more info and code for doing that in PHP at these links:

http://stackoverflow.com/questions/19821753/jquery-xml-error-no-access-control-allow-origin-header-is-present-on-the-req
http://stackoverflow.com/questions/12683530/origin-http-localhost-is-not-allowed-by-access-control-allow-origin

gogodr
Sr. Member
****
Offline Offline

Activity: 434
Merit: 250



View Profile
March 10, 2014, 04:54:02 AM
 #6

I use a work around for your problem here:
http://btca.frikicorp.com/
I use whateverorigin, it bypasses the cross domain control with a clever trick (setting up a local proxy)
I use the btc-e api here, but you can get the idea

$.getJSON('http://whateverorigin.org/get?url=https://btc-e.com/api/2/btc_usd/ticker&callback=?', function(data){
       BTCBuy = JSON.parse(data.contents).ticker.buy;
       BTCSell = JSON.parse(data.contents).ticker.sell;
      });
olsn
Newbie
*
Offline Offline

Activity: 55
Merit: 0


View Profile
March 10, 2014, 09:34:28 PM
 #7

I'd go with gogodr's solution, it'll be the simplest for you - BUT ONLY IF you just request public ticker data, you should in NO CASE send private user-data (passwords ect...) through 3rd-party proxy-services.
If you want to read more about JSONP and how to evade the cross-domain issue for JSON-requests, you can take a look here: http://en.wikipedia.org/wiki/JSONP (or google for JSONP)
RGBKey (OP)
Hero Member
*****
Offline Offline

Activity: 854
Merit: 658


rgbkey.github.io/pgp.txt


View Profile WWW
March 11, 2014, 12:59:07 AM
 #8

I'd go with gogodr's solution, it'll be the simplest for you - BUT ONLY IF you just request public ticker data, you should in NO CASE send private user-data (passwords ect...) through 3rd-party proxy-services.
If you want to read more about JSONP and how to evade the cross-domain issue for JSON-requests, you can take a look here: http://en.wikipedia.org/wiki/JSONP (or google for JSONP)
Thanks to gogodr, that should work just fine, and of course I'll only be using it for non-private information.
Zickafa
Member
**
Offline Offline

Activity: 112
Merit: 12


View Profile WWW
March 11, 2014, 06:43:32 PM
 #9

If you whant to make a site that would display API data from multiple exchanges and display it to the user use php better!
9inety7even
Member
**
Offline Offline

Activity: 84
Merit: 10


View Profile
March 11, 2014, 08:54:20 PM
 #10

I'd go with gogodr's solution, it'll be the simplest for you - BUT ONLY IF you just request public ticker data, you should in NO CASE send private user-data (passwords ect...) through 3rd-party proxy-services.
If you want to read more about JSONP and how to evade the cross-domain issue for JSON-requests, you can take a look here: http://en.wikipedia.org/wiki/JSONP (or google for JSONP)
Thanks to gogodr, that should work just fine, and of course I'll only be using it for non-private information.

The only other thing to be careful of is that you're now putting yourself in the hands of whateverorigin: they could send back false or even malicious data. Not that I have any reason to suspect that they would, but it's just something to think about.

If you whant to make a site that would display API data from multiple exchanges and display it to the user use php better!

He could still be using PHP; he just wants the client to load the information instead of doing it on the server.

gogodr
Sr. Member
****
Offline Offline

Activity: 434
Merit: 250



View Profile
March 11, 2014, 11:07:31 PM
 #11

I'd go with gogodr's solution, it'll be the simplest for you - BUT ONLY IF you just request public ticker data, you should in NO CASE send private user-data (passwords ect...) through 3rd-party proxy-services.
If you want to read more about JSONP and how to evade the cross-domain issue for JSON-requests, you can take a look here: http://en.wikipedia.org/wiki/JSONP (or google for JSONP)
Thanks to gogodr, that should work just fine, and of course I'll only be using it for non-private information.

The only other thing to be careful of is that you're now putting yourself in the hands of whateverorigin: they could send back false or even malicious data. Not that I have any reason to suspect that they would, but it's just something to think about.

If you whant to make a site that would display API data from multiple exchanges and display it to the user use php better!

He could still be using PHP; he just wants the client to load the information instead of doing it on the server.
if that ever were to happen, they have their whole project open sourced. Anyone can take the source and make his own whateverorigin.
There are a couple of limitations though. you cant POST or GET parameters using whateverorigin.
RGBKey (OP)
Hero Member
*****
Offline Offline

Activity: 854
Merit: 658


rgbkey.github.io/pgp.txt


View Profile WWW
March 12, 2014, 12:37:25 AM
 #12

I'd go with gogodr's solution, it'll be the simplest for you - BUT ONLY IF you just request public ticker data, you should in NO CASE send private user-data (passwords ect...) through 3rd-party proxy-services.
If you want to read more about JSONP and how to evade the cross-domain issue for JSON-requests, you can take a look here: http://en.wikipedia.org/wiki/JSONP (or google for JSONP)
Thanks to gogodr, that should work just fine, and of course I'll only be using it for non-private information.

The only other thing to be careful of is that you're now putting yourself in the hands of whateverorigin: they could send back false or even malicious data. Not that I have any reason to suspect that they would, but it's just something to think about.

If you whant to make a site that would display API data from multiple exchanges and display it to the user use php better!

He could still be using PHP; he just wants the client to load the information instead of doing it on the server.
I really want to do as much as I can in javascript and will only resort to PHP as a last resort. Also, a MITM is no problem because all i'm fetching is ticker data. They can't really do anything with that and nothing important is going to be stored on the site anyways.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!