Bitcoin Forum
December 04, 2016, 02:35:34 PM *
News: To be able to use the next phase of the beta forum software, please ensure that your email address is correct/functional.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Last price from Mt Gox json  (Read 1123 times)
Jeremy West spendbitcoins.com
Hero Member
*****
Offline Offline

Activity: 686



View Profile WWW
August 07, 2011, 08:15:43 PM
 #1

Can anyone help? I'm trying to grab the last price from Mt Gox using the following code:

<?php
    $url = 'https://mtgox.com/api/0/data/ticker.php';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_REFERER, $url);
    $json = curl_exec($ch);
    curl_close($ch);
    echo $json;//['ticker']['last'];
?>

and it's just hanging. Can anyone spot an error or if it's completely wrong just give me the right code? 1 BTC bounty if it works!

Thanks!

1480862134
Hero Member
*
Offline Offline

Posts: 1480862134

View Profile Personal Message (Offline)

Ignore
1480862134
Reply with quote  #2

1480862134
Report to moderator
1480862134
Hero Member
*
Offline Offline

Posts: 1480862134

View Profile Personal Message (Offline)

Ignore
1480862134
Reply with quote  #2

1480862134
Report to moderator
1480862134
Hero Member
*
Offline Offline

Posts: 1480862134

View Profile Personal Message (Offline)

Ignore
1480862134
Reply with quote  #2

1480862134
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1480862134
Hero Member
*
Offline Offline

Posts: 1480862134

View Profile Personal Message (Offline)

Ignore
1480862134
Reply with quote  #2

1480862134
Report to moderator
1480862134
Hero Member
*
Offline Offline

Posts: 1480862134

View Profile Personal Message (Offline)

Ignore
1480862134
Reply with quote  #2

1480862134
Report to moderator
jackjack
Hero Member
*****
Offline Offline

Activity: 868


May Bitcoin be touched by his Noodly Appendage


View Profile
August 07, 2011, 08:41:51 PM
 #2

Here's what I usually use
Code:
<?php
$a
=ouvrirpage("https://mtgox.com/code/data/ticker.php");
$res=json_decode($atrue);
echo 
$res['ticker']['last'];


function 
ouvrirpage($site){
$ch curl_init($site);
curl_setopt($chCURLOPT_USERAGENT"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
curl_setopt($chCURLOPT_RETURNTRANSFER1);
$res curl_exec($ch);
curl_close($ch);
return $res;
}
?>

Maybe MtGox needs an useragent header

Own address: 19QkqAza7BHFTuoz9N8UQkryP4E9jHo4N3 - Pywallet support: 1AQDfx22pKGgXnUZFL1e4UKos3QqvRzNh5 - Bitcointalk++ script support: 1Pxeccscj1ygseTdSV1qUqQCanp2B2NMM2
Pywallet: instructions. Encrypted wallet support, export/import keys/addresses, backup wallets, export/import CSV data from/into wallet, merge wallets, delete/import addresses and transactions, recover altcoins sent to bitcoin addresses, sign/verify messages and files with Bitcoin addresses, recover deleted wallets, etc.
wumpus
Hero Member
*****
Offline Offline

Activity: 798

No Maps for These Territories


View Profile
August 07, 2011, 08:42:47 PM
 #3

Yeah, you should use https://mtgox.com/code/data/ticker.php ... The URL that you use requires logging in.


Bitcoin Core developer [PGP] Warning: For most, coin loss is a larger risk than coin theft. A disk can die any time. Regularly back up your wallet through FileBackup Wallet to an external storage or the (encrypted!) cloud. Use a separate offline wallet for storing larger amounts.
markm
Legendary
*
Offline Offline

Activity: 1778



View Profile WWW
August 08, 2011, 01:50:33 AM
 #4

I read somewhere too that useragents that actually send a useragent field might be favoured over those  that do not?

(Dunno if bots would actually be requred to pretend to be (vanilla ?) browsers in order to be permitted to use the bot-enabling API though, has anyone tried being honest about which version of which bot is making the request?)

-MarkM-

Browser-launched Crossfire client now online (select CrossCiv server for Galactic  Milieu)
Free website hosting with PHP, MySQL etc: http://hosting.knotwork.com/
antares
Hero Member
*****
Offline Offline

Activity: 518


View Profile
August 08, 2011, 11:41:29 PM
 #5

acutally a user agent seems not to be required. In my android App I don't use one either. And It would not really make sense, at least when using the MtGox API, as this one is intended for non-browser traffic
brandon@sourcewerks
Member
**
Offline Offline

Activity: 62



View Profile
August 10, 2011, 04:00:59 PM
 #6

Just wanted to get it out there,  BOTs are easily written to appear as browsers or even do it the dirty way and run in the browser.

The useragent is configurable in the HTTP headers that you send with the request.  Also, MT.Gox likes a unique user-agent.
alkhdaniel
Member
**
Offline Offline

Activity: 114


View Profile
August 10, 2011, 05:20:53 PM
 #7

Code:
<?php
$opts 
= array(
  
'http'=> array(
    
'method'=>   "GET",
    
'user_agent'=>    "MozillaXYZ/1.0"));
$context stream_context_create($opts);
$json file_get_contents('https://mtgox.com/code/data/ticker.php'false$context);
$json json_decode($json);
echo 
$json->{'ticker'}->{'last'};
?>

Jeremy West spendbitcoins.com
Hero Member
*****
Offline Offline

Activity: 686



View Profile WWW
August 10, 2011, 09:06:06 PM
 #8

Sorry, forgot to post here that I already got this working with help from another thread. Thanks!

Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!