I want to integrate wikipedia in my iOS App (is it related to the mediawiki ?)
If so, I would like to know how I would tell wikipedia to give me an article about the o2 arena london (it is a one venue of London city) for example.
What would the url be for this example ?
I have searched in google and i have found this URL:
http://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles=o2%20arena%20london&rvprop=content&format=json&rvsection=0&rvparse=1
But this is not providing any data.
Is there any other URL ?
Wikipedia runs on MediaWiki (plus some customizations which are also available), so the answer to your first question is "Yes".
First you need to use the OpenSearch API to find which pages contain the information you want. Searching for o2 arena london is the following URL:
https://en.wikipedia.org/w/api.php?action=opensearch&search=o2+arena+london&format=jsonfm
which gives the following results:
[
"o2 arena london",
[
"O2 Arena London"
]
]
Using these results we can ask Wikipedia to return the HTML of the page. Here, the page "O2 Arena London" is a redirect to "O2 Arena (London)", so we need to ask Wikipedia to resolve the redirects and give us the final page. This is done using action=parse:
https://en.wikipedia.org/w/api.php?action=parse&redirects=1&page=O2+Arena+London&format=jsonfm
Which gives the following (shortened) results:
{
"parse": {
"title": "The O2 Arena",
"revid": 578231031,
"redirects": [
{
"from": "O2 Arena London",
"to": "The O2 Arena"
}
],
"text": {
"*": "<div class=\"dablink\">This article is about the indoor arena located in
London. For other uses, see <a href=\"/wiki/O2_Arena_(disambiguation)\"
title=\"O2 Arena (disambiguation)\" class=\"mw-redirect\">O2 Arena</a>.
...
You can display the result, but it may look weird without the CSS styling of Wikipedia.
Note, also, that if you want actual JSON, you would use format=json instead of format=jsonfm.
If you don't want to parse the wikipedia api output, why not
http://en.wikipedia.org/w/index.php?search=O2+arena+london
You just search for the words separated by +.
Related
I'm trying to classify a number of transport systems. I would like to use Schema.org markup but I can not find a category that covers these items.
I guess I need to create a custom "object". Can anyone give me a simple example of how to mark up my content?
The information could be like this:
Item: London Underground
City: London
Type: Metro
Number of lines: 10
Number of stations: 10
Basic fare: 1
Schedule: 00:00 - 23:00
…
Another one:
Item: Barcelona Bus Network
City: Barcelona
Type: Bus
Number of lines: 15
Number of stations: 200
…
You can't create a custom object the way you are asking, I believe you can get by using schema.org's Service though. Schema has some more specific service types, if each transport system in your list is government maintained, then perhaps you could use Government Service.
As far as how to mark up your content, you first need to decide how you want to add schema (e.g. microdata, RDFa, JSON-LD). The schema.org site has general examples that should help point you in the right direction on how to write one of those three. Here's an example code of a general service
I leave my answer, it can be useful to someone no matter how much time has passed.
The transport service has to be added under the service scheme. But if you don't want to leave out your local business, you can add that business as a service provider.
Here is an example of how it should be done.
{
"#context": "https://schema.org/",
"#type": "Service",
"provider": {
"#type": "LocalBusiness",
"name": "Litoral Trans"
},
"areaServed": {
"#type": "Status",
"name": "Santa Fe"
},
...
}
You can find good examples at the end of the following link https://schema.org/Service
I am trying to get realtime stock data from BSE and NSE using yahoo finance web-services. I was able to get some data using following URL
http://finance.yahoo.com/webservice/v1/symbols/COALINDIA.NS/quote?format=json
But it gives me very limited information.
{
"list": {
"meta": {
"type": "resource-list",
"start": 0,
"count": 1
},
"resources": [
{
"resource": {
"classname": "Quote",
"fields": {
"name": "COAL INDIA LTD",
"price": "367.649994",
"symbol": "COALINDIA.NS",
"ts": "1418895539",
"type": "equity",
"utctime": "2014-12-18T09:38:59+0000",
"volume": "2826975"
}
}
}
]
}
}
I need more information like yearly high, low, last traded price etc. and I couldn't find any documentation related to this from yahoo where it details how to get more information.
Is there documentation available related to these services? Or please suggest if there are any alternatives available.
I don't know where the definitive documentation might be but for your particular example try appending &view=detail to your URL.
http://finance.yahoo.com/webservice/v1/symbols/COALINDIA.NS/quote?format=json&view=detail
This will at least give you the year_high and year_low that you asked after.
Now, even though the following won't work for your COALINDIA.NS symbol (I suspect the exchange is not supported), it might be worth exploring the following two examples:
Example 1: As before, but for Apple and Yahoo symbols, with &view=detail appended:
http://finance.yahoo.com/webservice/v1/symbols/YHOO,AAPL/quote?format=json&view=detail
Example 2: And now using a completely different url, resulting in much more response data. One key caveat is this data is delayed by 15 minutes:
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20IN%20(%22YHOO%22,%22AAPL%22)&format=json&env=http://datatables.org/alltables.env
If you discover the major differences between those two options and what impact they might have then please do let us all know; I'd be interested in finding out more.
If you are fine with getting NSE qoutes, you can use this package for the purpose, it is extremely easy to setup.
http://nsetools.readthedocs.org/en/latest/index.html
Since it uses NSE website/services as data source, the quotes will not be delayed (max few seconds).
Beware that these data are both delayed and inconsistent. You are not getting anything even remotely close to tick or real-time data.
From example 2, refresh a few times, and inspect the "LastTradeWithTime" key-value pair. I sometimes get different quotes from different times of day, for no apparent reason. They are sometimes delayed up to three hours.
You get what you pay for; in other words, this is not a free lunch.
For those who are curious about the different options available in the Yahoo Finance URLs, I think these links might help. If it's not what you're looking for, sorry.
http://internetbandaid.com/2009/03/31/yahoo-stocks-api/
https://ilmusaham.wordpress.com/tag/stock-yahoo-data/
Note: the wordpress site contains information that was taken from a site called gummy-stuff.org which is listed in full at the bottom of the above site (I can only list 2 urls in this post so I had to do the round-about way). Oddly, I found this site on my own yesterday. Funny how stuff comes back around. If you visit this site you'll just see a statement from Yahoo that the info he had originally listed (you're looking at some of this site on the above wordpress site) was never intended to be for public consumption and is a violation of Yahoo's terms and conditions agreement as it can apparently be used for hacking purposes. I was curious to see what was on the original post so I searched for it on the WayBack Machine. BTW, the links to the spread sheets are still active in the archive.
Cheers. Thom
I am sending a request to Bing Maps REST service to get the location information such as coordinates etc, I entered this request (http://dev.virtualearth.net/REST/v1/Locations/query=rsa/gauteng/2001/johannesburg/melville?o=xml&key="mykey") in my web browser (as a test) and it returns the wrong location information.
The returned xml suggests that I'm in the states somewhere in NY.
Can anyone help me understand why this is?
I have read Microsoft's documentation on the web service and I'm following the proper structure to construct a request. I have Googled in a quest of getting a solution but no luck
You're not issuing the request correctly. Bing provides two methods: structured query and non-structured. You're mixing both.
Structured ("REST" like):
http://dev.virtualearth.net/REST/v1/Locations/CA/BC/V6G/Vancouver/Stanley%20Park%20Causeway?key=BingMapsKey
Non-structured (with query-string):
http://dev.virtualearth.net/REST/v1/Locations?locality=London&postalCode=SW1A&key=BingMapsKey
As specified on the reference page (http://msdn.microsoft.com/en-us/library/ff701714.aspx) a request similar to yours would need to be done like this:
http://dev.virtualearth.net/REST/v1/Locations?countryRegion={country}&adminDistrict={district}&locality={locality}&key={key}
Also, you should use the 2-letter ISO code. Thus, South-Africa would be "ZA".
Your complete request will be:
http://dev.virtualearth.net/REST/v1/Locations?countryRegion=za&adminDistrict=johannesburg&locality=melville&key=key
It returns something like this:
address: {
adminDistrict: "Gauteng",
adminDistrict2: "Johannesburg",
countryRegion: "South Africa",
formattedAddress: "Melville, South Africa",
locality: "Melville"
},
confidence: "High",
entityType: "Neighborhood",
geocodePoints: [{
type: "Point",
coordinates: [
-26.17535972595215,
28.008920669555664
],
calculationMethod: "Rooftop",
usageTypes: ["Display"]
}]
Introduction
/me/books.reads returns books[1].
It includes an array of books and the following fields for each book:
title
type
id
url
Problem
I'd like to get the author name(s) at least. I know that written_by is an existing field for books.
I'd like to get ISBN, if possible.
Current situation
I tried this:
/me/books.reads?fields=data.fields(author)
or
/me/books.reads?fields=data.fields(book.fields(author))
But the error response is:
"Subfields are not supported by data"
The books.reads response looks like this (just one book included):
{
"data": [
{
"id": "00000",
"from": {
"name": "User name",
"id": "11111"
},
"start_time": "2013-07-18T23:50:37+0000",
"publish_time": "2013-07-18T23:50:37+0000",
"application": {
"name": "Books",
"id": "174275722710475"
},
"data": {
"book": {
"id": "192511337557794",
"url": "https://www.facebook.com/pages/A-Semantic-Web-Primer/192511337557794",
"type": "books.book",
"title": "A Semantic Web Primer"
}
},
"type": "books.reads",
"no_feed_story": false,
"likes": {
"count": 0,
"can_like": true,
"user_likes": false
},
"comments": {
"count": 0,
"can_comment": true,
"comment_order": "chronological"
}
}
}
If I take the id of a book, I can get its metadata from the open graph, for example http://graph.facebook.com/192511337557794 returns something like this:
{
"category": "Book",
"description": "\u003CP>The development of the Semantic Web...",
"genre": "Computers",
"is_community_page": true,
"is_published": true,
"talking_about_count": 0,
"were_here_count": 0,
"written_by": "Grigoris Antoniou, Paul Groth, Frank Van Harmelen",
"id": "192511337557794",
"name": "A Semantic Web Primer",
"link": "http://www.facebook.com/pages/A-Semantic-Web-Primer/192511337557794",
"likes": 1
}
The response includes ~10 fields, including written_by which has the authors of the book.
Curiously, link field seems to map to url of the books.reads response. However, the field names are different, so I'm starting to loose hope that I would be able to ask for written_by in books.reads request..
The only reference that I've found about /me/books is https://developers.facebook.com/docs/reference/opengraph/object-type/books.book/
This is essentially about user sharing that he/she has read a book, not the details of the book itself.
The data structure is focused on the occasion of reading a book: when reading was started, when this story was published, etc.
[1] I know this thanks to How to get "read books"
FQl does not looks very promising – although you can request books from the user table, it seems to deliver just a string value with only the book titles comma-separated.
You can search page table by name – but I doubt it will work with name in (subquery) when what that subquery delivers is just one string of the format 'title 1,title 2,…'.
Can’t really test this right now, because I have read only one book so far (ahm, one that I have set as “books I read” on FB, not in general …) – but using that to search the page table by name already delivers a multitude of pages, and even if I narrow that selection down by AND is_community_page=1, I still get several, so no real way of telling which would be the right one, I guess.
So, using the Graph API and a batch request seems to be more promising.
Similar to an FQL multi-query, batch requests also allow you to refer data from the previous “operation” in a batch, by giving operations a “name”, and then referring to data from the first operation by using JSONPath expression format (see Specifying dependencies between operations in the request for details).
So a batch query for this could look like this,
[
{"method":"GET","name":"get-books","relative_url":"me\/books?fields=id"},
{"method":"GET","relative_url":"?ids={result=get-books:$.data.*.id}
&fields=description,name,written_by"}
]
Here all in one line, for easier copy&paste, so that line breaks don’t cause syntax errors:
[{"method":"GET","name":"get-books","relative_url":"me\/books?fields=id"},{"method":"GET","relative_url":"?ids={result=get-books:$.data.*.id}&fields=description,name,written_by"}]
So, to test this:
Go to Graph API Explorer.
Change method to POST via the dropdown, and clear whatever is in the field right next to it.
Click “Add a field”, and input name batch, and as value insert the line copy&pasted from above.
Since that will also get you a lot of “headers” you might not be interested in, you can add one more field, name include_headers and value false to get rid of those.
In the result, you will get a field named body, that contains the JSON-encoded data for the second query. If you want more fields, add them to the fields parameter of the second query, or leave that parameter out completely if you want all of them.
OK, after some trial-and-error I managed to create a direct link to Graph API Explorer to test this – the right amount of URL-encoding to use is a little fiddly to figure out :-)
(I left out the fields parameter for the second operation here, so this will give you all the info for the book that there is.)
As I said, I only got one book on FB, but this should work for a user with multiple books the same way (since the second operation just takes however many IDs it is given from the first one).
But I can’t tell you off the top of my head how this will work for a lot of books – how slow the second operation might get with that, when you set a high limit for the first one. And I also don’t know how this will behave in regard to pagination, which you might run into when me/books delivers a lot of books for a user.
But I think this should be a good enough starting point for you to figure the rest out by trying it on users with more data. HTH.
Edit: ISBN does not seem to be part of the info for a book’s community page, at least not for the ones I checked. And also written_by is optional – my book doesn’t have it. So you’ll only get that info if it is actually provided.
I'm trying to get the public posts for a specific subject with Facebook API en French for example (you need to change the access_token below) with this way :
https://graph.facebook.com/search?q=cinema&type=post&access_token=abc|abc&locale=fr_FR
This is not working. I have mixed languages (Spanish, French, English...) in the result. I checked the Facebook developers website and I cannot find a issue here. Somebody have the same problem?
In fact, if in the results, i have a lang key associated to each post, this would be good to me. I tried to add in the url fields=languages (and anothers words like lang,language,locale...) but this is not working too.
Thank you for your help! (sorry for my English)
graph.facebook.com/search?q=cinema&type=post&locale=fr_FR
In fact, when running this query, the locale parameter is considered. It gives categories translated in French.
{
"id": "376665779074901_525847047490106",
"from": {
"category": "Site internet de détente/sports",
"name": "Hasil+jadwal+klasemen Sepakbola",
"id": "376665779074901"
},
"message": "Hasil Pertandingan\n\nLike (y) & Bagikan ...\n\n• England- Premier League\nFT Chelsea 2 - 0 Fulham\nGoals :\n52'[1 - 0] Oscar\n84'[2 - 0] John Obi Mikel\n-\nFT Liverpool 0 - 1 Southampton\nGoals :\n54'[0 - 1] Dejan Lovren\n-\nFT Newcastle United 2 - 3 Hull City\nGoals :\n10'[1...
}
But I must agree, it's not really helpful. The least you could do would be, in the case of a user post, to check what is the language the user is using:
graph.facebook.com/USER_ID?field=locale
Apart from that, I have to say that you can't rely on Facebook's locale information. Facebook doesn't know if a post has been written in French or English. ALso, someone using Facebook in English doesn't mean he will only write english posts. If you want to find all messages in a specific language, better check all messages by yourself with another web service dedicated to language recognition.