NytUrl Simple API
Construct the URL:
http://nyturl.com/?save=y&url={http://(www).nytimes.com/path/to/valid/page.html}&format={response-format}
url: Any valid page or web page on NYTimes.com. This includes subdomains like 'travel.nytimes.com' and others.
format: Valid formats are "html" (default), "json", "xml", "csv". The HTML is the normal web page where you to do this manually.
CSV Example
URL
http://nyturl.com/?save=y&url=http://topics.nytimes.com/top/reference/timestopics/people/d/charles_robert_darwin/index.html&format=csv
Response on success
http://topics.nytimes.com/top/reference/timestopics/people/d/charles_robert_darwin/index.html,true,http://nyturl.com/19
Response on failure
http://topics.nytimes.com/top/reference/timestopics/people/d/charles_robert_darwin/index.html,false,Error message here
Sample PHP Code With CSV Result
<?php
require('simple_html_dom.php'); // http://sourceforge.net/projects/simplehtmldom/
/*
** Shorten a nytimes.com url
*/
function getNytUrl($url){
$html = file_get_html("http://nyturl.com/?save=y&format=csv&url=".$url);
preg_match('/http:\/\/nyturl\.com\/(.*)/', $html, $matches);
return "http://nyturl.com/".$matches[1];
}
?>
JSON Example
URL
http://nyturl.com/?save=y&url=http://topics.nytimes.com/top/reference/timestopics/people/d/charles_robert_darwin/index.html&format=json
Response on success
{'result': { 'request': 'http://topics.nytimes.com/top/reference/timestopics/people/d/charles_robert_darwin/index.html', 'success': true, 'url': 'http://nyturl.com/17' } }
Response on failure
{'result': { 'request': 'http://topics.nytimes.com/top/reference/timestopics/people/d/charles_robert_darwin/index.html', 'success': false, 'error': 'Error message here' } }
XML Example
URL
http://nyturl.com/?save=y&url=http://topics.nytimes.com/top/reference/timestopics/people/d/charles_robert_darwin/index.html&format=xml
Response on success
<?xml version="1.0" encoding="UTF-8"?>
<result>
<request>http://topics.nytimes.com/top/reference/timestopics/people/d/charles_robert_darwin/index.html</request>
<success>true</success>
<url>http://nyturl.com/17</url>
</result>
Response on failure
<?xml version="1.0" encoding="UTF-8"?>
<result>
<request>http://topics.nytimes.com/top/reference/timestopics/people/d/charles_robert_darwin/index.html</request>
<success>false</success>
<error>Error message here</error>
</result>
