Encode URL - Authentication parameters missing

Solved!
Posted in General by pashun Wed Oct 21 2015 10:41:45 GMT+0000 (UTC)·7·Viewed 1,459 times

I am having issues directly calling the api by appending authentication keys. Can you please provide me an example. Here is my non working url: https://api.aylien.com/api/v1/summarize?url=http%3A%2F%2Ftechcrunch.com%2F2015%2F10%2F20%2Fgoogle-to-the-yahoo-rescue%2F&sentences_number=5&X-AYLIEN-TextAPI-Application-Key%3A+"mykey"&X-AYLIEN-TextAPI-Application-ID%3A+"myid"
Hamed Ramezanian
Oct 21, 2015

Hi, Thanks for opening issue.

Auth keys are header parameters, you can't use them as query parameters. As you can see in the documentation, you can use curl for calling the API.

curl https://api.aylien.com/api/v1/summarize \
   -H "X-AYLIEN-TextAPI-Application-Key: YOUR_APP_KEY" \
   -H "X-AYLIEN-TextAPI-Application-ID: YOUR_APP_ID" \
   -d sentences_number=5 \
   -d url="http://techcrunch.com/2015/10/20/google-to-the-yahoo-rescue"

Also feel free to use our SDKs, currently we have SDK for NodeJs, Python, PHP, Java, Ruby, Go and C# programming languages.

pashun
Oct 21, 2015

Thanks Hamed. Another basic question. If I use your sample javascript code, where do I pass the keys?

textapi.summarize({
url: 'http://techcrunch.com/2015/04/06/john-oliver-just-changed-the-surveillance-reform-debate',
sentences_number: 3
}, function(error, response) {
if (error === null) {
response.sentences.forEach(function(s) {
console.log(s);
});
}
});

pashun
Oct 21, 2015

Never mind my previous question. If there is a way to use the script in googleapps script that would be great. Not from the addon.

Hamed Ramezanian
Oct 22, 2015

There is UrlFetchApp class in googleapps which is actually an HTTP client. Here is a sample code:

var options = {
  headers: {
    "X-AYLIEN-TextAPI-Application-Key": "YOUR_APP_KEY",
    "X-AYLIEN-TextAPI-Application-ID": "YOUR_APP_ID"
  }
};
var result = UrlFetchApp.fetch("https://api.aylien.com/api/v1/summarize?url=http://techcrunch.com/2015/10/20/google-to-the-yahoo-rescue", options);
Mina Khan
Dec 30, 2015

following doesn't work. here's the error:
Fetch API cannot load https://api.aylien.com/api/v1/sentiment. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

var AYLIENTextAPI = require('aylien_textapi');
var textapi = new AYLIENTextAPI({
application_id: "APP_ID",
application_key: "APP_KEY"
});
textapi.sentiment({
'text': 'John is a very good football player!'
}, function(error, response) {
if (error === null) {
console.log(response);
}
});

Hamed Ramezanian
Jan 4, 2016

Hi,

Currently we don't support 'Access-Control-Allow-Origin' header that means you can't use our API directly in a JavaScript file which runs in browser. In order to solve this problem, you need to write a simple backend application as a proxy and then use the proxy in you JavaScript app.


Amir M. Saeid marked this as solved
Markdown is allowed