Re: [CODE4LIB] ny times best seller api
Some of OCLC's APIs do support JSONP or CORS: for example QuestionPoint API, the xIdentifier and MapFAST services. However, other services do not provide this support. This is because for these services we need to carefully ensure that the application making the request is actually owned by the institution/user to which the key has been issued. If we don't do this then there are several consequences 1. We aren't able to clearly distinguish who is using a given service. This fundamentally makes it more difficult for us to keep statistics and evaluate the value of our services to the OCLC membership. 2. Users/Institutions not eligible to use particular services are able to access those services. 3. Other users/institutions may be able to see data which is private and specific to a particular institution We know that developers want to use our APIs in Javascripts. As a result we're working really hard on potential solutions that would allow us to both provide this type of access and ensure that the application making the request of the API is coming from an appropriate authorized institution/user. If anyone has further questions, they are welcome to email me directly. Karen Karen Coombs Product Manager OCLC Developer Network coom...@oclc.org On Mon, Oct 3, 2011 at 8:21 AM, Ed Summers wrote: > On Wed, Sep 28, 2011 at 5:36 PM, Godmar Back wrote: >> Closer to the code4lib community: OCLC and Serials Solutions don't support >> JSONP in their webservices, either, even though doing so would allow cool >> services and would likely not affect their business models adversely in a >> significant way, IMO. We should keep lobbying them to remove these >> restrictions, as I've been doing for a while. > > I agree. I'm not sure how pervasive it is at OCLC, but their MapFast > Service supports Cross Origin Resource Sharing (CORS) [1,2], which > means that JSONP isn't needed for modern browsers. Basically it's just > adding the following header to the JSON response: > > Access-Control-Allow-Origin: * > > Something to think about when creating a web service for others, at any rate. > > [1] http://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing > [2] http://inkdroid.org/journal/2011/02/09/oclcs-mapfast-and-cors/ >
Re: [CODE4LIB] ny times best seller api
On Wed, Sep 28, 2011 at 5:36 PM, Godmar Back wrote: > Closer to the code4lib community: OCLC and Serials Solutions don't support > JSONP in their webservices, either, even though doing so would allow cool > services and would likely not affect their business models adversely in a > significant way, IMO. We should keep lobbying them to remove these > restrictions, as I've been doing for a while. I agree. I'm not sure how pervasive it is at OCLC, but their MapFast Service supports Cross Origin Resource Sharing (CORS) [1,2], which means that JSONP isn't needed for modern browsers. Basically it's just adding the following header to the JSON response: Access-Control-Allow-Origin: * Something to think about when creating a web service for others, at any rate. [1] http://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing [2] http://inkdroid.org/journal/2011/02/09/oclcs-mapfast-and-cors/
Re: [CODE4LIB] ny times best seller api
On Fri, Sep 30, 2011 at 11:52 AM, Doug Yancey wrote: > I've put an example of the php file (extension changed to .txt), along with > the stylesheet I'm using in the following directory on our webserver: > > http://nc.ccrls.org/code4lib/ Thank you. I'll take a look. > I was going to build a caching strategy into the php script itself, but > recently discovered that our webserver can do output caching. So I'm > exploring that right now and want it working before this little project > goes > live. I think it will improve performance, since these pages don't have to > be up-to-the-minute current, and keep us well away from the NYT api limits. > The Reading Radar caches pages too. I imagine they would have a real concern with API limits (unless the NY Times gives them a break). > My only lingering question is whether or not this setup compromises my > developer key. I don't think it does, since that key is included in the > php > file itself and isn't visible in the output. However, if others detect an > issue here, I'd be grateful to hear about it. > One never knows how an API "vendor" will react, but given that the NY Times features the Reading Radar in their API gallery, and it has had a lot of traffic since it went live in 2009, I can't imagine that would have any objection to yours or anybody else's. http://developer.nytimes.com/reading_radar_app Karen Coyle seems to have been involved with the bestseller API in the context of developing a WorldCat book ordering system. http://www.oclc.org/developer/news/building-new-york-times-bestsellers-application There are only screenshots provided; no working example or code. I don't know if this has progressed past the prototype stage, but it is a really nice idea. Tom Tom
Re: [CODE4LIB] ny times best seller api
Tom, Wasn't aware of the Reading Radar portal - thanks for sharing that. I've put an example of the php file (extension changed to .txt), along with the stylesheet I'm using in the following directory on our webserver: http://nc.ccrls.org/code4lib/ I was going to build a caching strategy into the php script itself, but recently discovered that our webserver can do output caching. So I'm exploring that right now and want it working before this little project goes live. I think it will improve performance, since these pages don't have to be up-to-the-minute current, and keep us well away from the NYT api limits. My only lingering question is whether or not this setup compromises my developer key. I don't think it does, since that key is included in the php file itself and isn't visible in the output. However, if others detect an issue here, I'd be grateful to hear about it. Regards, Doug On Thu, Sep 29, 2011 at 4:27 PM, Tom Keays wrote: > On Wed, Sep 28, 2011 at 5:38 PM, Doug Yancey wrote: > >I just got this set up on our site, using php to parse the json response. > > You should be able to see the result on our staging port at: > > > >http://catalog.ccrls.org:2082 > > > >...under the 'Bestsellers' menu in the top nav bar. > > Nice. It reminds me of the Reading Radar portal, written using the > Maintainable PHP Framework. > > http://readingradar.com/ > https://github.com/maintainable/framework > > > would be happy to share that code with you, if you think it would > >help. > > The author of Reading Radar described the structure of his mashup, but > didn't follow up with any code. It would be great to see yours. > > > http://jhherren.wordpress.com/2009/02/03/mashing-up-the-new-york-times-best-sellers-readingradarcom/ > > > On Wed, Sep 28, 2011 at 5:36 PM, Godmar Back wrote: > >NYTimes could allow JSONP, but then developers would need to embed their > API > >key in their web pages, which means the API key would simply be a token > used > >for statistics, rather than for authentication. It's their choice that > they > >don't allow that. > > I saw several threads in the NY Times developer forum, one as far back as > 2009, where a JSONP option had been promised by NY Times staff. It may not > be coming. > > However, given that the API is read-only, I don't see the real consequence > of using keys in the open. > > > Tom > -- Doug Yancey Chemeketa Cooperative Regional Library Service Web Services Librarian 503.315.4268 Need support from CCRLS? Open a ticket at http://swhelpdesk.ccrls.org/portal
Re: [CODE4LIB] ny times best seller api
On Wed, Sep 28, 2011 at 5:38 PM, Doug Yancey wrote: >I just got this set up on our site, using php to parse the json response. > You should be able to see the result on our staging port at: > >http://catalog.ccrls.org:2082 > >...under the 'Bestsellers' menu in the top nav bar. Nice. It reminds me of the Reading Radar portal, written using the Maintainable PHP Framework. http://readingradar.com/ https://github.com/maintainable/framework > would be happy to share that code with you, if you think it would >help. The author of Reading Radar described the structure of his mashup, but didn't follow up with any code. It would be great to see yours. http://jhherren.wordpress.com/2009/02/03/mashing-up-the-new-york-times-best-sellers-readingradarcom/ On Wed, Sep 28, 2011 at 5:36 PM, Godmar Back wrote: >NYTimes could allow JSONP, but then developers would need to embed their API >key in their web pages, which means the API key would simply be a token used >for statistics, rather than for authentication. It's their choice that they >don't allow that. I saw several threads in the NY Times developer forum, one as far back as 2009, where a JSONP option had been promised by NY Times staff. It may not be coming. However, given that the API is read-only, I don't see the real consequence of using keys in the open. Tom
Re: [CODE4LIB] ny times best seller api
Because a few people have asked me about this off list, and because I'm now struggling with a different related question, I'm bringing it back to the list for all. If it's TMI, just delete the email and move on... sorry to jam your inbox. But I'm determined to make this thing work. I have the proxy working fine as Godmar suggested, but I'm doing something wrong parsing the JSON. Thanks- I learn an awful lot by interacting with this list. *Here's the PHP for the proxy:* http://api.nytimes.com/svc/books/v2/lists/hardcover-fiction.json?&api-key= ' ); header("Content-Type: text/javascript"); echo $cb . '(' . $json . ')'; ?> *Here's the jQuery:* jQuery(document).ready(function(){ $(function(){ //json request to new york times $.getJSON(' http://www.sjpl.org/otherscripts/callback.php?callback=?', function(data) { //loop through the results with the following function $.each(data.results[0].book_details, function(i,item){ //turn the title into a variable var bookTitle = item.title; $.each(data.results[0].isbns, function(i,item){ //turn the isbn into a variable var bookIsbn = item.isbn13; $('#container').append('http://catalog.sjlibrary.org/search~/a?searchtype=i&searcharg='+bookIsbn+'&SORT=D&searchscope=1">'+bookTitle+''); }); }); }); }); }); *Here's my problem:* I can only return the book title and the isbn by specifying which one in the array I want, so I'm using: data.results[0].book_details to pull the first title. Something is wrong with the way I'm using $.each() If I remove [0] and have data.results.book_details I get no result. If I add [1] and have data.results[1].book_details I get the same result twice. If I add [2] and have data.results[2].book_details I get the same result three times. I'm sure I'm doing something dumb with my syntax. Any ideas? *Here's a bigger chunk of the JSON, since I'm having problems moving through it.* { "status": "OK", "copyright": "Copyright (c) 2011 The New York Times Company. All Rights Reserved.", "num_results": 35, "last_modified": "2011-09-23T12:00:29-04:00", "results": [{ "list_name": "Hardcover Fiction", "display_name": "Hardcover Fiction", "updated": "WEEKLY", "bestsellers_date": "2011-09-17", "published_date": "2011-10-02", "rank": 1, "rank_last_week": 0, "weeks_on_list": 1, "asterisk": 0, "dagger": 0, "isbns": [{ "isbn10": "0399157786", "isbn13": "9780399157783" }], "book_details": [{ "title": "NEW YORK TO DALLAS", "description": "An escaped child molester pursues Lt. Eve Dallas; by Nora Roberts, writing pseudonymously.", "contributor": "by J. D. Robb", "author": "J D Robb", "contributor_note": "", "price": 27.95, "age_group": "", "publisher": "Putnam", "primary_isbn13": "9780399157783", "primary_isbn10": "0399157786" }], "reviews": [{ "book_review_link": "", "first_chapter_link": "", "sunday_review_link": "", "article_chapter_link": "" }] }, { "list_name": "Hardcover Fiction", "display_name": "Hardcover Fiction", "updated": "WEEKLY", "bestsellers_date": "2011-09-17", "published_date": "2011-10-02", "rank": 2, "rank_last_week": 0, "weeks_on_list": 1, "asterisk": 0, "dagger": 0, "isbns": [{ "isbn10": "0385534639", "isbn13": "9780385534635" }, { "isbn10": "0385534647", "isbn13": "9780385534642" }], "book_details": [{ "title": "THE NIGHT CIRCUS", "description": "Two young rivals at a magical circus become collaborators as they fall in love.", "contributor": "by Erin Morgenstern", "author": "Erin Morgenstern", "contributor_note": "", "price": 26.95, "age_group": "", "publisher": "Doubleday", "primary_isbn13": "9780385534635", "primary_isbn10": "0385534639" }], "reviews": [{ "book_review_link": "", "first_chapter_link": "", "sunday_review_link": "", "article_chapter_link": "" }] }, { "list_name": "Hardcover Fiction", "display_name": "Hardcover Fiction", "updated": "WEEKLY", "bestsellers_date": "2011-09-17", "published_date": "2011-10-02", "rank": 3, "rank_last_week": 1, "weeks_on_list": 3, "asteris
Re: [CODE4LIB] ny times best seller api
On Wed, Sep 28, 2011 at 5:02 PM, Michael B. Klein wrote: > > It's not NYTimes.com's fault; it's the cross-site scripting jerks who made > the security necessary in the first place. > > NYTimes could allow JSONP, but then developers would need to embed their API key in their web pages, which means the API key would simply be a token used for statistics, rather than for authentication. It's their choice that they don't allow that. Closer to the code4lib community: OCLC and Serials Solutions don't support JSONP in their webservices, either, even though doing so would allow cool services and would likely not affect their business models adversely in a significant way, IMO. We should keep lobbying them to remove these restrictions, as I've been doing for a while. - Godmar
Re: [CODE4LIB] ny times best seller api
I just got this set up on our site, using php to parse the json response. You should be able to see the result on our staging port at: http://catalog.ccrls.org:2082 ...under the 'Bestsellers' menu in the top nav bar. We're having to host the actual php pages on a separate web server, since our ILS server can't be made to support it. Being a total php newb, I received some great help from the stackoverflow forum to get the script working; would be happy to share that code with you, if you think it would help. I've also tagged these pages for google analytics, so that we can monitor the traffic on them. I doubt we would come anywhere near the 5000/day api limit, but wanted to be sure. And I suppose if we did, I could always introduce some server-side caching to cut the number down. Regards, Doug On Wed, Sep 28, 2011 at 12:28 PM, Nate Hill wrote: > Anybody out there using the NY times best seller API to do stuff on their > library websites? > I can't figure out what's wrong with my code here. > Data is returned as "null"; I can't seem to parse the response with jQuery. > Any help would be supercool. > I removed the API key - my code doesn't actually contain ''. > Here's the jQuery: > > jQuery(document).ready(function(){ >$(function(){ >//json request to new york times >$.getJSON(' > > http://api.nytimes.com/svc/books/v2/lists/hardcover-fiction.json?&api-key= > ', > >function(data) { >//loop through the results with the following > function >$.each(data.results.book_details, function(i,item){ >//turn the title into a variable >var bookTitle = item.title; >$('#container').append(''+bookTitle+''); > >}); >}); >}); > }); > > > Here's a snippet of the JSON response: > > { >"status": "OK", >"copyright": "Copyright (c) 2011 The New York Times Company. All Rights > Reserved.", >"num_results": 35, >"last_modified": "2011-09-23T12:00:29-04:00", >"results": [{ >"list_name": "Hardcover Fiction", >"display_name": "Hardcover Fiction", >"updated": "WEEKLY", >"bestsellers_date": "2011-09-17", >"published_date": "2011-10-02", >"rank": 1, >"rank_last_week": 0, >"weeks_on_list": 1, >"asterisk": 0, >"dagger": 0, >"isbns": [{ >"isbn10": "0399157786", >"isbn13": "9780399157783" >}], >"book_details": [{ >"title": "NEW YORK TO DALLAS", >"description": "An escaped child molester pursues Lt. Eve > Dallas; by Nora Roberts, writing pseudonymously.", >"contributor": "by J. D. Robb", >"author": "J D Robb", >"contributor_note": "", >"price": 27.95, >"age_group": "", >"publisher": "Putnam", >"primary_isbn13": "9780399157783", >"primary_isbn10": "0399157786" >}], >"reviews": [{ >"book_review_link": "", >"first_chapter_link": "", >"sunday_review_link": "", >"article_chapter_link": "" >}] > > > -- > Nate Hill > nathanielh...@gmail.com > http://www.natehill.net > -- Doug Yancey Chemeketa Cooperative Regional Library Service Web Services Librarian 503.315.4268 Need support from CCRLS? Open a ticket at http://swhelpdesk.ccrls.org/portal
Re: [CODE4LIB] ny times best seller api
You can pull data from their API into a server-side process and then pass it along (filtered or raw) to your browser. But browser security won't let you access JSON data from a different-origin server. It's not NYTimes.com's fault; it's the cross-site scripting jerks who made the security necessary in the first place. On Wed, Sep 28, 2011 at 1:26 PM, Nate Hill wrote: > Wait- what would be the point of their API if I couldn't run anything on a > domain other than nytimes.com? > Thanks everyone for the pointers. I'll get back to it! > If I can pull the first 5 titles from the different best seller lists, and > then using the ISBN build a link to those titles in the library catalog, I > will have made something useful which I will gladly share back to the list. > > On Wed, Sep 28, 2011 at 1:23 PM, Godmar Back wrote: > > > Are you trying to run this inside a webpage served from a domain other > than > > nytimes.com? > > If so, you'd need to use JSONP, which a cursory examination of their API > > documentation reveals they do not support. So, you need to use a proxy. > > > > Here's one: > > $ cat hardcover.php > > > $cb = @$_GET['callback']; > > > > $json = file_get_contents(' > > > > > http://api.nytimes.com/svc/books/v2/lists/hardcover-fiction.json?&api-key= > > ' > > ); > > header("Content-Type: text/javascript"); > > echo $cb . '(' . $json . ')'; > > > > ?> > > > > Install it on your webserver, then change your JavaScript code to refer > to > > it using callback=?. > > > > For instance, if you installed it on > > http://libx.lib.vt.edu/services/nytimes/hardcover.php > > then you would be using the URL > > http://libx.lib.vt.edu/services/nytimes/hardcover.php?callback=? > > (.getJSON will replace the ? with a suitably generated function name). > > > > - Godmar > > > > On Wed, Sep 28, 2011 at 3:28 PM, Nate Hill > > wrote: > > > > > Anybody out there using the NY times best seller API to do stuff on > their > > > library websites? > > > I can't figure out what's wrong with my code here. > > > Data is returned as "null"; I can't seem to parse the response with > > jQuery. > > > Any help would be supercool. > > > I removed the API key - my code doesn't actually contain ''. > > > Here's the jQuery: > > > > > > jQuery(document).ready(function(){ > > >$(function(){ > > >//json request to new york times > > >$.getJSON(' > > > > > > > > > http://api.nytimes.com/svc/books/v2/lists/hardcover-fiction.json?&api-key= > > > ', > > > > > >function(data) { > > >//loop through the results with the following > > > function > > >$.each(data.results.book_details, > > function(i,item){ > > >//turn the title into a variable > > >var bookTitle = item.title; > > >$('#container').append(''+bookTitle+''); > > > > > >}); > > >}); > > >}); > > > }); > > > > > > > > > Here's a snippet of the JSON response: > > > > > > { > > >"status": "OK", > > >"copyright": "Copyright (c) 2011 The New York Times Company. All > > Rights > > > Reserved.", > > >"num_results": 35, > > >"last_modified": "2011-09-23T12:00:29-04:00", > > >"results": [{ > > >"list_name": "Hardcover Fiction", > > >"display_name": "Hardcover Fiction", > > >"updated": "WEEKLY", > > >"bestsellers_date": "2011-09-17", > > >"published_date": "2011-10-02", > > >"rank": 1, > > >"rank_last_week": 0, > > >"weeks_on_list": 1, > > >"asterisk": 0, > > >"dagger": 0, > > >"isbns": [{ > > >"isbn10": "0399157786", > > >"isbn13": "9780399157783" > > >}], > > >"book_details": [{ > > >"title": "NEW YORK TO DALLAS", > > >"description": "An escaped child molester pursues Lt. Eve > > > Dallas; by Nora Roberts, writing pseudonymously.", > > >"contributor": "by J. D. Robb", > > >"author": "J D Robb", > > >"contributor_note": "", > > >"price": 27.95, > > >"age_group": "", > > >"publisher": "Putnam", > > >"primary_isbn13": "9780399157783", > > >"primary_isbn10": "0399157786" > > >}], > > >"reviews": [{ > > >"book_review_link": "", > > >"first_chapter_link": "", > > >"sunday_review_link": "", > > >"article_chapter_link": "" > > >}] > > > > > > > > > -- > > > Nate Hill > > > nathanielh...@gmail.com > > > http://www.natehill.net > > > > > > > > > -- > Nate Hill > nathanielh...@gmail.com > http://www.natehill.net >
Re: [CODE4LIB] ny times best seller api
Wait- what would be the point of their API if I couldn't run anything on a domain other than nytimes.com? Thanks everyone for the pointers. I'll get back to it! If I can pull the first 5 titles from the different best seller lists, and then using the ISBN build a link to those titles in the library catalog, I will have made something useful which I will gladly share back to the list. On Wed, Sep 28, 2011 at 1:23 PM, Godmar Back wrote: > Are you trying to run this inside a webpage served from a domain other than > nytimes.com? > If so, you'd need to use JSONP, which a cursory examination of their API > documentation reveals they do not support. So, you need to use a proxy. > > Here's one: > $ cat hardcover.php > $cb = @$_GET['callback']; > > $json = file_get_contents(' > > http://api.nytimes.com/svc/books/v2/lists/hardcover-fiction.json?&api-key= > ' > ); > header("Content-Type: text/javascript"); > echo $cb . '(' . $json . ')'; > > ?> > > Install it on your webserver, then change your JavaScript code to refer to > it using callback=?. > > For instance, if you installed it on > http://libx.lib.vt.edu/services/nytimes/hardcover.php > then you would be using the URL > http://libx.lib.vt.edu/services/nytimes/hardcover.php?callback=? > (.getJSON will replace the ? with a suitably generated function name). > > - Godmar > > On Wed, Sep 28, 2011 at 3:28 PM, Nate Hill > wrote: > > > Anybody out there using the NY times best seller API to do stuff on their > > library websites? > > I can't figure out what's wrong with my code here. > > Data is returned as "null"; I can't seem to parse the response with > jQuery. > > Any help would be supercool. > > I removed the API key - my code doesn't actually contain ''. > > Here's the jQuery: > > > > jQuery(document).ready(function(){ > >$(function(){ > >//json request to new york times > >$.getJSON(' > > > > > http://api.nytimes.com/svc/books/v2/lists/hardcover-fiction.json?&api-key= > > ', > > > >function(data) { > >//loop through the results with the following > > function > >$.each(data.results.book_details, > function(i,item){ > >//turn the title into a variable > >var bookTitle = item.title; > >$('#container').append(''+bookTitle+''); > > > >}); > >}); > >}); > > }); > > > > > > Here's a snippet of the JSON response: > > > > { > >"status": "OK", > >"copyright": "Copyright (c) 2011 The New York Times Company. All > Rights > > Reserved.", > >"num_results": 35, > >"last_modified": "2011-09-23T12:00:29-04:00", > >"results": [{ > >"list_name": "Hardcover Fiction", > >"display_name": "Hardcover Fiction", > >"updated": "WEEKLY", > >"bestsellers_date": "2011-09-17", > >"published_date": "2011-10-02", > >"rank": 1, > >"rank_last_week": 0, > >"weeks_on_list": 1, > >"asterisk": 0, > >"dagger": 0, > >"isbns": [{ > >"isbn10": "0399157786", > >"isbn13": "9780399157783" > >}], > >"book_details": [{ > >"title": "NEW YORK TO DALLAS", > >"description": "An escaped child molester pursues Lt. Eve > > Dallas; by Nora Roberts, writing pseudonymously.", > >"contributor": "by J. D. Robb", > >"author": "J D Robb", > >"contributor_note": "", > >"price": 27.95, > >"age_group": "", > >"publisher": "Putnam", > >"primary_isbn13": "9780399157783", > >"primary_isbn10": "0399157786" > >}], > >"reviews": [{ > >"book_review_link": "", > >"first_chapter_link": "", > >"sunday_review_link": "", > >"article_chapter_link": "" > >}] > > > > > > -- > > Nate Hill > > nathanielh...@gmail.com > > http://www.natehill.net > > > -- Nate Hill nathanielh...@gmail.com http://www.natehill.net
Re: [CODE4LIB] ny times best seller api
Are you trying to run this inside a webpage served from a domain other than nytimes.com? If so, you'd need to use JSONP, which a cursory examination of their API documentation reveals they do not support. So, you need to use a proxy. Here's one: $ cat hardcover.php http://api.nytimes.com/svc/books/v2/lists/hardcover-fiction.json?&api-key=' ); header("Content-Type: text/javascript"); echo $cb . '(' . $json . ')'; ?> Install it on your webserver, then change your JavaScript code to refer to it using callback=?. For instance, if you installed it on http://libx.lib.vt.edu/services/nytimes/hardcover.php then you would be using the URL http://libx.lib.vt.edu/services/nytimes/hardcover.php?callback=? (.getJSON will replace the ? with a suitably generated function name). - Godmar On Wed, Sep 28, 2011 at 3:28 PM, Nate Hill wrote: > Anybody out there using the NY times best seller API to do stuff on their > library websites? > I can't figure out what's wrong with my code here. > Data is returned as "null"; I can't seem to parse the response with jQuery. > Any help would be supercool. > I removed the API key - my code doesn't actually contain ''. > Here's the jQuery: > > jQuery(document).ready(function(){ >$(function(){ >//json request to new york times >$.getJSON(' > > http://api.nytimes.com/svc/books/v2/lists/hardcover-fiction.json?&api-key= > ', > >function(data) { >//loop through the results with the following > function >$.each(data.results.book_details, function(i,item){ >//turn the title into a variable >var bookTitle = item.title; >$('#container').append(''+bookTitle+''); > >}); >}); >}); > }); > > > Here's a snippet of the JSON response: > > { >"status": "OK", >"copyright": "Copyright (c) 2011 The New York Times Company. All Rights > Reserved.", >"num_results": 35, >"last_modified": "2011-09-23T12:00:29-04:00", >"results": [{ >"list_name": "Hardcover Fiction", >"display_name": "Hardcover Fiction", >"updated": "WEEKLY", >"bestsellers_date": "2011-09-17", >"published_date": "2011-10-02", >"rank": 1, >"rank_last_week": 0, >"weeks_on_list": 1, >"asterisk": 0, >"dagger": 0, >"isbns": [{ >"isbn10": "0399157786", >"isbn13": "9780399157783" >}], >"book_details": [{ >"title": "NEW YORK TO DALLAS", >"description": "An escaped child molester pursues Lt. Eve > Dallas; by Nora Roberts, writing pseudonymously.", >"contributor": "by J. D. Robb", >"author": "J D Robb", >"contributor_note": "", >"price": 27.95, >"age_group": "", >"publisher": "Putnam", >"primary_isbn13": "9780399157783", >"primary_isbn10": "0399157786" >}], >"reviews": [{ >"book_review_link": "", >"first_chapter_link": "", >"sunday_review_link": "", >"article_chapter_link": "" >}] > > > -- > Nate Hill > nathanielh...@gmail.com > http://www.natehill.net >
Re: [CODE4LIB] ny times best seller api
and nothing specific to this case, but i've taken to developing using .ajax() instead of the .getJSON(), etc. .ajax underlies all the others, but i've had better luck debugging/diagnosing with the lower-level function. On Wed, Sep 28, 2011 at 3:28 PM, Nate Hill wrote: > Anybody out there using the NY times best seller API to do stuff on their > library websites? > I can't figure out what's wrong with my code here. > Data is returned as "null"; I can't seem to parse the response with jQuery. > Any help would be supercool. > I removed the API key - my code doesn't actually contain ''. > Here's the jQuery: > > jQuery(document).ready(function(){ > $(function(){ > //json request to new york times > $.getJSON(' > http://api.nytimes.com/svc/books/v2/lists/hardcover-fiction.json?&api-key=', > > function(data) { > //loop through the results with the following > function > $.each(data.results.book_details, function(i,item){ > //turn the title into a variable > var bookTitle = item.title; > $('#container').append(''+bookTitle+''); > > }); > }); > }); > }); > > > Here's a snippet of the JSON response: > > { > "status": "OK", > "copyright": "Copyright (c) 2011 The New York Times Company. All Rights > Reserved.", > "num_results": 35, > "last_modified": "2011-09-23T12:00:29-04:00", > "results": [{ > "list_name": "Hardcover Fiction", > "display_name": "Hardcover Fiction", > "updated": "WEEKLY", > "bestsellers_date": "2011-09-17", > "published_date": "2011-10-02", > "rank": 1, > "rank_last_week": 0, > "weeks_on_list": 1, > "asterisk": 0, > "dagger": 0, > "isbns": [{ > "isbn10": "0399157786", > "isbn13": "9780399157783" > }], > "book_details": [{ > "title": "NEW YORK TO DALLAS", > "description": "An escaped child molester pursues Lt. Eve > Dallas; by Nora Roberts, writing pseudonymously.", > "contributor": "by J. D. Robb", > "author": "J D Robb", > "contributor_note": "", > "price": 27.95, > "age_group": "", > "publisher": "Putnam", > "primary_isbn13": "9780399157783", > "primary_isbn10": "0399157786" > }], > "reviews": [{ > "book_review_link": "", > "first_chapter_link": "", > "sunday_review_link": "", > "article_chapter_link": "" > }] > > > -- > Nate Hill > nathanielh...@gmail.com > http://www.natehill.net >
Re: [CODE4LIB] ny times best seller api
that said if you are hoping to get reviews i had very low results. i was hoping they included reviews for things that might not have made the best sellers but most of what i tried in some sample searches came up blank. haven't bothers doing much with the historical best seller data otherwise. eby On Wed, Sep 28, 2011 at 3:59 PM, Gabriel Farrell wrote: > Looks like data.results is an array, so you'll have to loop through > it. If you just want the first result, you could get at the > book_details array with data.results[0].book_details. > > On Wed, Sep 28, 2011 at 3:28 PM, Nate Hill wrote: >> Anybody out there using the NY times best seller API to do stuff on their >> library websites? >> I can't figure out what's wrong with my code here. >> Data is returned as "null"; I can't seem to parse the response with jQuery. >> Any help would be supercool. >> I removed the API key - my code doesn't actually contain ''. >> Here's the jQuery: >> >> jQuery(document).ready(function(){ >> $(function(){ >> //json request to new york times >> $.getJSON(' >> http://api.nytimes.com/svc/books/v2/lists/hardcover-fiction.json?&api-key=', >> >> function(data) { >> //loop through the results with the following >> function >> $.each(data.results.book_details, function(i,item){ >> //turn the title into a variable >> var bookTitle = item.title; >> $('#container').append(''+bookTitle+''); >> >> }); >> }); >> }); >> }); >> >> >> Here's a snippet of the JSON response: >> >> { >> "status": "OK", >> "copyright": "Copyright (c) 2011 The New York Times Company. All Rights >> Reserved.", >> "num_results": 35, >> "last_modified": "2011-09-23T12:00:29-04:00", >> "results": [{ >> "list_name": "Hardcover Fiction", >> "display_name": "Hardcover Fiction", >> "updated": "WEEKLY", >> "bestsellers_date": "2011-09-17", >> "published_date": "2011-10-02", >> "rank": 1, >> "rank_last_week": 0, >> "weeks_on_list": 1, >> "asterisk": 0, >> "dagger": 0, >> "isbns": [{ >> "isbn10": "0399157786", >> "isbn13": "9780399157783" >> }], >> "book_details": [{ >> "title": "NEW YORK TO DALLAS", >> "description": "An escaped child molester pursues Lt. Eve >> Dallas; by Nora Roberts, writing pseudonymously.", >> "contributor": "by J. D. Robb", >> "author": "J D Robb", >> "contributor_note": "", >> "price": 27.95, >> "age_group": "", >> "publisher": "Putnam", >> "primary_isbn13": "9780399157783", >> "primary_isbn10": "0399157786" >> }], >> "reviews": [{ >> "book_review_link": "", >> "first_chapter_link": "", >> "sunday_review_link": "", >> "article_chapter_link": "" >> }] >> >> >> -- >> Nate Hill >> nathanielh...@gmail.com >> http://www.natehill.net >> >
Re: [CODE4LIB] ny times best seller api
Looks like data.results is an array, so you'll have to loop through it. If you just want the first result, you could get at the book_details array with data.results[0].book_details. On Wed, Sep 28, 2011 at 3:28 PM, Nate Hill wrote: > Anybody out there using the NY times best seller API to do stuff on their > library websites? > I can't figure out what's wrong with my code here. > Data is returned as "null"; I can't seem to parse the response with jQuery. > Any help would be supercool. > I removed the API key - my code doesn't actually contain ''. > Here's the jQuery: > > jQuery(document).ready(function(){ > $(function(){ > //json request to new york times > $.getJSON(' > http://api.nytimes.com/svc/books/v2/lists/hardcover-fiction.json?&api-key=', > > function(data) { > //loop through the results with the following > function > $.each(data.results.book_details, function(i,item){ > //turn the title into a variable > var bookTitle = item.title; > $('#container').append(''+bookTitle+''); > > }); > }); > }); > }); > > > Here's a snippet of the JSON response: > > { > "status": "OK", > "copyright": "Copyright (c) 2011 The New York Times Company. All Rights > Reserved.", > "num_results": 35, > "last_modified": "2011-09-23T12:00:29-04:00", > "results": [{ > "list_name": "Hardcover Fiction", > "display_name": "Hardcover Fiction", > "updated": "WEEKLY", > "bestsellers_date": "2011-09-17", > "published_date": "2011-10-02", > "rank": 1, > "rank_last_week": 0, > "weeks_on_list": 1, > "asterisk": 0, > "dagger": 0, > "isbns": [{ > "isbn10": "0399157786", > "isbn13": "9780399157783" > }], > "book_details": [{ > "title": "NEW YORK TO DALLAS", > "description": "An escaped child molester pursues Lt. Eve > Dallas; by Nora Roberts, writing pseudonymously.", > "contributor": "by J. D. Robb", > "author": "J D Robb", > "contributor_note": "", > "price": 27.95, > "age_group": "", > "publisher": "Putnam", > "primary_isbn13": "9780399157783", > "primary_isbn10": "0399157786" > }], > "reviews": [{ > "book_review_link": "", > "first_chapter_link": "", > "sunday_review_link": "", > "article_chapter_link": "" > }] > > > -- > Nate Hill > nathanielh...@gmail.com > http://www.natehill.net >
[CODE4LIB] ny times best seller api
Anybody out there using the NY times best seller API to do stuff on their library websites? I can't figure out what's wrong with my code here. Data is returned as "null"; I can't seem to parse the response with jQuery. Any help would be supercool. I removed the API key - my code doesn't actually contain ''. Here's the jQuery: jQuery(document).ready(function(){ $(function(){ //json request to new york times $.getJSON(' http://api.nytimes.com/svc/books/v2/lists/hardcover-fiction.json?&api-key=', function(data) { //loop through the results with the following function $.each(data.results.book_details, function(i,item){ //turn the title into a variable var bookTitle = item.title; $('#container').append(''+bookTitle+''); }); }); }); }); Here's a snippet of the JSON response: { "status": "OK", "copyright": "Copyright (c) 2011 The New York Times Company. All Rights Reserved.", "num_results": 35, "last_modified": "2011-09-23T12:00:29-04:00", "results": [{ "list_name": "Hardcover Fiction", "display_name": "Hardcover Fiction", "updated": "WEEKLY", "bestsellers_date": "2011-09-17", "published_date": "2011-10-02", "rank": 1, "rank_last_week": 0, "weeks_on_list": 1, "asterisk": 0, "dagger": 0, "isbns": [{ "isbn10": "0399157786", "isbn13": "9780399157783" }], "book_details": [{ "title": "NEW YORK TO DALLAS", "description": "An escaped child molester pursues Lt. Eve Dallas; by Nora Roberts, writing pseudonymously.", "contributor": "by J. D. Robb", "author": "J D Robb", "contributor_note": "", "price": 27.95, "age_group": "", "publisher": "Putnam", "primary_isbn13": "9780399157783", "primary_isbn10": "0399157786" }], "reviews": [{ "book_review_link": "", "first_chapter_link": "", "sunday_review_link": "", "article_chapter_link": "" }] -- Nate Hill nathanielh...@gmail.com http://www.natehill.net