Yahoo Finance API Error - yahoo-api

I was just wondering if this code is the right API for yahoo finance because it does not work. If someone has the right API I would love to hear a response.
Here is the code.
let urlString:String = ("https://query.yahooapis.com/v1/public/yql?q=select *
from yahoo.finance.quotes where symbol IN
"+stringQuotes+"&format=json&env=http://datatables.org/alltables.env").stringByAdd
ingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!

there is an issue at the moment with http://datatables.org/
seems the website is not responding which makes all the yql queries for Community Data tables not to work.
Seems it has been down for about 12 hours. I hope they don't shut it down :(
Your url is missing the brackets surronding stringQuotes (just thought of mentioning in case your string variable "stringQuotes" does not have it)
let urlString:String = ("https://query.yahooapis.com/v1/public/yql?q=select *
from yahoo.finance.quotes where symbol IN
("+stringQuotes+")&format=json&env=http://datatables.org/alltables.env").stringByAdd
ingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!

Related

POST request using Power Query

I'm trying to collect data from the major electronic components distributors using their API with Power Query.
I was able to do it easily with ARROW and FARNELL as they use a GET request but now I'm trying to do the same thing with MOUSER but it's a POST request.
Here's the code I've written so far but it's not working :
edit
Can someone please help me and tell me what's wrong ?
The API documentation is here:
https://api.mouser.com/api/docs/ui/index#/SearchApi/SearchApi_SearchByPartNumber
Thanks for your help !
edit
My first attempt was really awful, I've made a few changes but it's still not working:
let
url = "https://api.mouser.com/api/v1.0/search/partnumber?apiKey=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
body = Json.FromValue({[SearchByPartRequest = ""], [mouserPartNumber = "LL4148"], [partSearchOptions = "3"]}),
Source = Json.Document(Web.Contents(url, [Headers=[#"Content-
Type"="application/json"], Content = body]))
in
Source
edit
I get the following error:
error message (from Power Query or the API ?)
The answer you're looking for is in the Web.Contents() function.
You can read more information here, here, and here.

Retrieve TSX intra-day quote from Alphavantage

I've been able to get the daily quote for TSX marketing using this endpoint, and it has been working perfectly.
https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=TSX:BTO&apikey={{key}}
But when I try to get intraday data (60 minutes) with the following request, it doesn't work.
https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&interval=60min&symbol=TSX:BTO&apikey={{key}}
RESPONSE
{
Error Message: "Invalid API call. Please retry or visit the documentation (https://www.alphavantage.co/documentation/) for TIME_SERIES_INTRADAY."
}
Is this because they don't offer intraday data for TSX or did I do anything wrong?
Thanks!
Use symbol=BTO.TO in your URL for both
Longer explanation:
There are a number of different methods for mapping tickers - generally the best method is:
symbol.exchange
See the wiki for more information

The definitive guide to posting a Facebook Feed item using pure C#

Does anyone have a definitive way to post to a user's wall, using nothing but the .NET Framework, or Silverlight?
Problems deriving from people's attempts have been asked here on SO, but I cannot find a full, clear explanation of the Graph API spec and a simple example using WebClient or some similar class from System.Net.
Do I have to send all feed item properties as parameters in the query string? Can I construct a JSON object to represent the feed item and send that (with the access token as the only parameter)?
I expect its no more than a 5 line code snippet, else, point me at the spec in the FB docs.
Thanks for your help,
Luke
This is taken from how we post to a user's wall. We place the data for the post in the request body (I think we found this to be more reliable than including all the parameters in the query part of the request), it has the same format as a URL encoded query string.
I agree that the documentation is rather poor at explaining how to interact with a lot of resources. Typically I look at the documentation for information on fields and connections, then work with the Graph API Explorer to understand how the request needs to be constructed. Once I've got that down it's pretty easy to implement in C# or whatever. The only SDK I use is Facebook's Javascript SDK. I've found the others (especially 3rd party) are more complicated, buggy, or broken than rolling my own.
private void PostStatus (string accessToken, string userId)
{
UriBuilder address = new UriBuilder ();
address.Scheme = "https";
address.Host = "graph.facebook.com";
address.Path = userId + "/feed";
address.Query = "access_token=" + accessToken;
StringBuilder data = new StringBuilder ();
data.Append ("caption=" + HttpUtility.UrlEncodeUnicode ("Set by app to describe the app."));
data.Append ("&link=" + HttpUtility.UrlEncodeUnicode ("http://example.com/some_resource_to_go_to_when_clicked"));
data.Append ("&description=" + HttpUtility.UrlEncodeUnicode ("Message set by user."));
data.Append ("&name=" + HttpUtility.UrlEncodeUnicode ("App. name"));
data.Append ("&picture=" + HttpUtility.UrlEncodeUnicode ("http://example.com/image.jpg"));
WebClient client = new WebClient ();
string response = client.UploadString (address.ToString (), data.ToString ());
}
I don't know much about .net or silverlight, but the facebook api works with simple http requests.
All the different sdks (with the exception of the javascript one) are mainly just wrappers for the http requests with the "feature" of adding the access token to all requests.
Not in all requests the parameters are sent as querystring, in some POST requests you need to send them in the request body (application/x-www-form-urlencoded), and you can not send the data as json.
If the C# sdk is not to your liking, you can simply create one for your exact needs.
As I wrote, you just need to wrap the requests, and you can of course have a method that will get a json as parameter and will break it to the different parameters to be sent along with the request.
I would point you to the facebook documentation but you haven't asked anything specific so there's nothing to point you to except for the landing page.

finding both "Shopping_mall" and "food" within single URL for google places API

I tried following URLs to get both "shopping_mall" and "food" within a single request.
https://maps.googleapis.com/maps/api/place/search/json?location=%#,%#&radius=1500&sensor=true&key=%#&types=shopping_mall|food
This gives me response with only "food" type of places.
But,
https://maps.googleapis.com/maps/api/place/search/json?location=%#,%#&radius=1500&sensor=true&key=%#&types=shopping_mall
Gives the result with "shopping_mall" only. Also, The same URL with "food" only give the result same as "shopping_mall|food".
Has anyone faced this issue. I have searched across but cannot find any useful answer to that.
P.S. I have gone through this link and this link , too.
If you are getting only food in the first request, and you're getting 20 results, then it is likely Google believes the most relevant results are food. You may have to do 2 requests. You can try adding keyword=shopping, but that may limit your food results.

Nothing except "None" returned for my Python web.py Facebook app when I turn on "OAuth 2.0 for Canvas"

I am a beginning Facebook app developer, but I'm an experienced developer. I'm using web.py as my web framework, and to make matters a bit worse, I'm new to Python.
I'm running into an issue, where when I try to switch over to using the newer "OAuth 2.0 for Canvas", I simply can't get anything to work. The only thing being returned in my Facebook app is "None".
My motivation for turning on OAuth 2.0 is because it sounds like Facebook is going to force it by July, and I might as well learn it now and now have to rewrite it in a few weeks.
I turned on "OAuth 2.0 for Canvas" in the Advanced Settings, and rewrote my code to look for "signed_request" that is POSTed to my server whenever my test user tries to access my app.
My code is the following (I've removed debugging statements and error checking for brevity):
#!/usr/bin/env python
import base64
import web
import minifb
import urllib
import json
FbApiKey = "AAAAAA"
FbActualSecret = "BBBBBB"
CanvasURL = "http://1.2.3.4/fb/"
RedirectURL="http://apps.facebook.com/CCCCCCCC/"
RegURL = 'https://graph.facebook.com/oauth/authorize?client_id=%s&redirect_uri=%s&type=user_agent&display=page' % (FbApiKey, RedirectURL)
urls = (
'/fb/', 'index',
)
app = web.application(urls, locals())
def authorize():
args = web.input()
signed_request = args['signed_request']
#split the signed_request via the .
strings = signed_request.split('.')
hmac = strings[0]
encoded = strings[1]
#since uslsafe_b64decode requires padding, add the proper padding
numPads = len(encoded) % 4
encoded = encoded + "=" * numPads
unencoded = base64.urlsafe_b64decode(str(encoded))
#convert signedRequest into a dictionary
signedRequest = json.loads(unencoded)
try:
#try to find the oauth_token, if it's not there, then
#redirect to the login page
access_token = signedRequest['oauth_token']
print(access_token)
except:
print("Access token not found, redirect user to login")
redirect = "<script type=\"text/javascript\">\ntop.location.href=\"" +_RegURL + "\";\n</script>"
print(redirect)
return redirect
# Do something on the canvas page
returnString = "<html><body>Hello</body></html>"
print(returnString)
class index:
def GET(self):
authorize()
def POST(self):
authorize()
if __name__ == "__main__":
app.run()
For the time being, I want to concentrate on the case where the user is already logged in, so assume that oauth_token is found.
My question is: Why is my "Hello" not being outputted, and instead all I see is "None"?
It appears that I'm missing something very fundamental, because I swear to you, I've scoured the Internet for solutions, and I've read the Facebook pages on this many times. Similarly, I've found many good blogs and stackoverflow questions that document precisely how to use OAuth 2.0 and signed_request. But the fact that I am getting a proper oauth_token, but my only output is "None" makes me think there is something fundamental that I'm doing incorrectly. I realize that "None" is a special word in python, so maybe that's the cause, but I can't pin down exactly what I'm doing wrong.
When I turn off OAuth 2.0, and revert my code to look for the older POST data, I'm able to easily print stuff to the screen.
Any help on this would be greatly appreciated!
How embarrassing!
In my authorize function, I return a string. But since class index is calling authorize, it needs to be returned from the class, not from authorize. If I return the return from authorize, it works.