- Home /
WWW yield is not returning any value in ios for yahoo finance api
Hi All,
I am getting the stock value from yahoo finance and displaying it in a Text UI component. The below code is working fine in Windows PC, Mac, Android mobile but not in iOS. Code is not getting executed after " yield return wwwEricA;" only for yahoo finance http link "http://finance.yahoo.com/d/quotes.csv?s=ERIC-A.ST&f=sl1d1t1c1p2ohgv&e=.csv" . For testing i have given "https://www.google.co.in/" and that is returning value in ios mobile also. So i guess the problem is only with that particular yahoo URL but could not find what is that. Please help me to solve this issue.
Code :
public Text EricAStockText;
private WWW wwwEricA;
private string stockUrlEricA;
private string[] stockArrayEricA;
private char[] seperators = { ',' };
void Start()
{
stockUrlEricA = "http://finance.yahoo.com/d/quotes.csv?s=" + WWW.EscapeURL("ERIC-A.ST&f=sl1d1t1c1p2ohgv&e=.csv");
StartCoroutine(GetStockValueA(stockUrlEricA));
}
private IEnumerator GetStockValueA(string URL)
{
wwwEricA = new WWW(URL);
yield return wwwEricA;
stockArrayEricA = ParseStockValue(wwwEricA.text, seperator);
EricAStockText.text = stockArrayEricA[1];
}
private string[] ParseStockValue(string valueString, char[] seperator)
{
return valueString.Split(seperator, System.StringSplitOptions.RemoveEmptyEntries);
}
Answer by Bunny83 · May 05, 2016 at 10:19 AM
You use "EscapeURL" wrong. You escaped the "&" in your URL but you actually want them there. Your generated URL would look like this:
"http://finance.yahoo.com/d/quotes.csv?s=ERIC-A.ST%26f%3Dsl1d1t1c1p2ohgv%26e%3D.csv"
So your "equals" (=) and "ampersands" (&) are replaced with %26 and %3D. So the server only sees one parameter ("s") which contains that rest as one string.
You should only exscape the content of your URL parameters.
stockUrlEricA = "http://finance.yahoo.com/d/quotes.csv?s=" + WWW.EscapeURL("ERIC-A.ST") + "&f=" + WWW.EscapeURL("sl1d1t1c1p2ohgv") + "&e=" + WWW.EscapeURL(".csv");
This would be the correct way to form your URL. However if you use a hardcoded URL you don't need EscapeURL at all since your data don't contain any problematic characters.
See URL Encoding for more details.
@Bunny83 Thanks for your suggestion, actual problem is with the URL This below URL solved the problem "http://download.finance.yahoo.com/d/quotes.csv?s=ERIC-A.ST&f=sl1d1t1c1p2ohgv&e=.csv"
Answer by Harrymon12 · Jul 12, 2017 at 03:42 PM
Yahoo finance API is not available anymore. I have moved to MarketXLS after this change, much more reliable data.