User offline. Last seen 1 week 3 days ago. Offline
Joined: 04/30/2008

If you use JavaScript to send the content and use ‘escape(myContent)’ function to escape the content, you will need to change it to: ‘encodeURIComponent(myContent)’

For example:

               var clfsws = new XMLHttpRequest();

                clfsws.open("POST", "http://api.opencalais.com/enlighten/rest/", true);

                clfsws.onreadystatechange = function() { _this.swsStateChangeCallback(); };

                clfsws.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

                clfsws.setRequestHeader('User-Agent', 'My very very smart user agent');

                clfsws.send("licenseID=thisismylicenseid&content=" + encodeURIComponent(content) + '&paramsXML=' + encodeURIComponent('<c:params xmlns:c="http://s.opencalais.com/1/pred/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><c:processingDirectives c:contentType="text/txt" c:outputFormat="text/gnosis" c:discardMetadata=";"></c:processingDirectives><c:userDirectives c:allowDistribution="true" c:allowSearch="true" c:externalID="calaisbridge" c:submitter="calaisbridge"></c:userDirectives><c:externalMetadata c:caller="GnosisFirefox"/></c:params>'));

                                } catch (ex) {

                                                if (getShowAlert())

             alert(gnosis.stringsBundle.getString('errorSending'));

                                                dump(ex);

                                }

Trackback URL for this post:

http://www.opencalais.com/trackback/23677

Login or Register to post a comment.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
User offline. Last seen 1 year 8 weeks ago. Offline
Joined: 06/29/2013

I am trying to follow the JavaScript sample at http://www.opencalais.com/documentation/calais-web-service-api/faq-calais-api. The send() method seems to be failing--I think the problem lies there.

var clfsws = new XMLHttpRequest();
clfsws.open("POST", "http://api.opencalais.com/enlighten/rest/", true);
clfsws.onreadystatechange = function() { _this.swsStateChangeCallback(); };
clfsws.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
clfsws.setRequestHeader('User-Agent', 'My very very smart user agent');

clfsws.send("licenseID=xxxxxxxxxxxx&content="+ encodeURIComponent(content)
+ '&paramsXML='
+ encodeURIComponent(content) + '&paramsXML=' + encodeURIComponent(''));

document.write('clfsws.readyState: ');
document.write(clfsws.readyState);
document.write('clfsws.status: ');
document.write(clfsws.status);

In Firefox, when this code executes,
clfsws.readyState = 1
clfsws.status = 0

In Safari and the default browser of my IDE,
clfsws.readyState = 1
clfsws.status = --> An exception is thrown and caught when I try to access this value.

I'm pretty sure the licenseID I'm using is valid.

Thanks.

User offline. Last seen 3 years 29 weeks ago. Offline
Joined: 01/27/2011

Hi, I have written the following code to access the openCalais API through jQuery. The request works find and I can see the results in Firebug, but am unable to access the data returned. the code is as follows:

baseUrl = "http://api.opencalais.com/enlighten/rest/";
licenseID = "abcdefg12345";
content = "went snoboarding with my friend in whistler.....blah blah blah";
paramsXml = '';

var completeReqUrl = baseUrl + "?licenseID=" + licenseID + "&content=" + content + "&paramsXML=" + encodeURIComponent(paramsXml);

var postData = "licenseID=" + licenseID + "&content=" + content + "&paramsXML=" + encodeURIComponent(paramsXml);

var req = $.ajax(
{
url: completeReqUrl ,
type: "GET",
dataType: "script",

success: function(data, statux, xhr)
{
console.log(data);
console.log(status);
console.log(xhr);
},
error: function(error, status)
{
console.log(error);
console.log(status);
}
});

the success callback never fires, and neither does the error callback. any ideas?

User offline. Last seen 1 year 41 weeks ago. Offline
Joined: 10/05/2009
Hi, I'm trying to call the OpenCalais API using jQuery's Ajax plugin.

The code is similar to the below:

$.ajax({
type:"GET",
data:"licenseID=etc&content=etc,paramsXML=etc",
success:function(result) {
          document.write(result);
        }
});

The data is properly encoded and I have a valid license key
but every time I try this out I receive a "Mashery" error code 
something along the lines of "ERR_569_SERVICE_NOT_FOUND" when 
debugging any calls form the page.

I have also tried the simplest way of doing this using 
"var etc = new XMLHttpRequest();" and setting up like one of 
the FAQs here explained but still receive the same problem.

Using an actual form and pressing submit works fine.

Has anyone used Ajax to call the API before? Or even has a working example? 

The above returns that error message for me.

Thanks,
Dan

User offline. Last seen 4 years 46 weeks ago. Offline
Joined: 09/22/2009

"http://api.opencalais.com/enlighten/rest/" is not working, but "http://api1.opencalais.com/enlighten/rest/" is ok !