0

I am working on Yahoo stock data. Yesterday I got the stock data by using finance web service api. But today when I am trying to get the data from api I am getting the below error:

{
   "p": {
      "a": {
         "href": "https://finance.yahoo.com/webservice/v1/symbols/msft,goog,appl,orcl,yhoo,tcs,amzn,INFY.NS/quote?bypass=true&format=json&view=detail",
         "content": "https://finance.yahoo.com/webservice/v1/symbols/msft,goog,appl,orcl,yhoo,tcs,amzn,INFY.NS/quote?bypass=true&format=json&view=detail"
      },
      "content": "Moved Temporarily. Redirecting to"
   }
}

Saying that it was moved temporarily.
Why am I getting this error? Did I reach the API limit for today?

NOTE:
Yesterday I kept it running to test the API request limit. But when I am trying to run today it showing the above error.

If the API limit for IP is reached then when do I get access to the data again?
This is the API which I am using:

http://finance.yahoo.com/webservice/v1/symbols/msft,goog,appl,orcl,yhoo,tcs,amzn,INFY.NS/quote?format=json&view=detail
Till Helge
  • 9,253
  • 2
  • 40
  • 56
bunny sunny
  • 301
  • 6
  • 15

2 Answers2

1

As it was commented here: https://stackoverflow.com/a/38390559/6586718, you have to change the user-agent to a mobile device.

On Java, I do the following, and it's working (this is for XML, but the same can be applied to JSON):

URL url = new URL ("https://finance.yahoo.com/webservice/v1/symbols/" + stocks + "/quote");
HttpURLConnection urlc = (HttpURLConnection) url.openConnection ();
urlc.setRequestProperty ("User-Agent", "Mozilla/5.0 (Linux; Android 6.0; MotoE2(4G-LTE) Build/MPI24.65-39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.81 Mobile Safari/537.36");
Document xml = DocumentBuilderFactory.newInstance ().newDocumentBuilder ().parse (urlc.getInputStream ());
Community
  • 1
  • 1
  • Thank you @Carlos Its working fine and able to retreive data from api. But can you tell me what does changing user-agent to mobile device means ? – bunny sunny Jul 18 '16 at 04:55
  • The user agent tells the server where the call is coming from. Here you can read more about it: https://en.wikipedia.org/wiki/User_agent#Use_in_HTTP In this case, we are tricking the server into thinking that the call is coming from a **mobile web browser**, because that is what it is accepting. The moment it detects that is coming from somewhere else (for example, a PC browser, or a Java program), it redirects to a different page and the API doesn't work anymore. By the way, if the answer solved your problem, please mark it as 'solved'. Thanks! –  Jul 18 '16 at 09:53
0

try with this new one..

https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20csv%20where%20url%3D'http%3A%2F%2Fdownload.finance.yahoo.com%2Fd%2Fquotes.csv%3Fs%3DAAPL%26f%3Dsl1d1t1c1ohgv%26e%3D.csv'%20and%20columns%3D'symbol%2Cprice%2Cdate%2Ctime%2Cchange%2Ccol1%2Chigh%2Clow%2Ccol2'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys

  • Welcome to Stack Overflow! A link to a potential solution is always welcome, but please [add context around the link](http://meta.stackoverflow.com/a/8259/169503) so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline. Take into account that being *barely more than a link to an external site* is a possible reason as to [Why and how are some answers deleted?](http://stackoverflow.com/help/deleted-answers) – Lahiru Jayaratne Aug 06 '16 at 03:08