2015-07-20 44 views
2

我正在使用craigslist的批量發佈api。我寫了一個快速的腳本,看起來像這樣:Node.js - Craigslist批量發佈api(解析rss失敗)

var https = require('https'); 
var posting = '<?xml version="1.0"?><rdf:RDF xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cl="http://www.craigslist.org/about/cl-bulk-ns/1.0"><channel><items><rdf:li rdf:resource="NYCBrokerHousingSample1"/><rdf:li rdf:resource="NYCBrokerHousingSample2"/></items><cl:auth username="[email protected]" password="example" accountID="14"/></channel><item rdf:about="NYCBrokerHousingSample1"><cl:category>fee</cl:category><cl:area>nyc</cl:area><cl:subarea>mnh</cl:subarea><cl:neighborhood>Upper West Side</cl:neighborhood><cl:housingInfo price="1450" bedrooms="0" sqft="600"/><cl:replyEmail privacy="C">[email protected]</cl:replyEmail><cl:brokerInfo companyName="Joe Sample and Associates" feeDisclosure="fee disclosure here" /><title>Spacious Sunny Studio in Upper West Side</title><description><![CDATA[posting body here]]></description></item><item rdf:about="NYCBrokerHousingSample2"><cl:category>fee</cl:category><cl:area>nyc</cl:area><cl:subarea>mnh</cl:subarea><cl:neighborhood>Chelsea</cl:neighborhood><cl:housingInfo price="2175" bedrooms="1" sqft="850" catsOK="1"/><cl:mapLocation city="New York" state="NY" crossStreet1="23rd Street" crossStreet2="9th Avenue" latitude="40.746492" longitude="-74.001326"/><cl:replyEmail privacy="C" otherContactInfo="212.555.1212">[email protected]</cl:replyEmail><cl:brokerInfo companyName="Joe Sample and Associates" feeDisclosure="fee disclosure here" /><title>1BR Charmer in Chelsea</title><description><![CDATA[posting body goes here]]></description><cl:PONumber>Purchase Order 094122</cl:PONumber></item></rdf:RDF>' 

var options = { 
    hostname: 'post.craigslist.org', 
    path: '/bulk-rss/validate', 
    method: 'POST', 
    headers: { 
    'Content-Type' : 'application/x-www-form-urlencoded' 
    } 
}; 

var req = https.request(options, function(res) { 
    console.log("headers: ", res); 

    res.on('data', function(d) { 
    process.stdout.write(d); 
    }); 
}); 
req.write(posting) 
req.end() 

req.on('error', function(e) { 
    console.error(e); 
}); 

我正在與附加消息no element found at line 1, column 0, byte -1 415不支持的媒體類型響應。 XML是直接從他們的例子,所以它似乎應該不會有問題解析XML,除非有問題,我怎麼發送https請求。

回答

0

爲了通過Craigslist批量發佈API進行發佈,您必須擁有一個PAID帳戶,您需要通過電話進行驗證,並且每次發佈都需要付費。這可能是爲什麼它不起作用。