Real-time and historical news content at your fingertips
We monitor thousands of news outlets in real time to give you an enriched and flexible news data feed. With our News API you can easily search, analyze, and leverage enriched news content in your modeling processes.
An end-to-end News Intelligence solution
SDKs and Code Snippets
Get up and running in minutes rather than days
Please select
Installation
go get github.com/AYLIEN/aylien_newsapi_go
Import and initiate the SDK
package main
// Import the library
import (
"context"
"fmt"
newsapi "github.com/AYLIEN/aylien_newsapi_go"
"os"
"github.com/antihax/optional"
)
func main() {
cfg := newsapi.NewConfiguration()
cfg.DefaultHeader["X-AYLIEN-NewsAPI-Application-ID"] = os.Getenv("NEWSAPI_APP_ID")
// Configure API key authorization: app_key
cfg.DefaultHeader["X-AYLIEN-NewsAPI-Application-Key"] = os.Getenv("NEWSAPI_APP_KEY")
client := newsapi.NewAPIClient(cfg)
api := client.DefaultApi
storiesParams := &newsapi.ListStoriesOpts{
Title: optional.NewString("trump"),
NotLanguage: optional.NewInterface([]string{"en"}),
PublishedAtStart: optional.NewString("NOW-7DAYS"),
PublishedAtEnd: optional.NewString("NOW"),
EntitiesBodyLinksDbpedia: optional.NewInterface([]string{
"http://dbpedia.org/resource/Donald_Trump",
}),
}
storiesResponse, res, err := api.ListStories(context.Background(), storiesParams)
if err != nil {
panic(err)
}
_ = res
for _, story := range storiesResponse.Stories {
fmt.Println(story.Title, " / ", story.Source.Name)
}
}
Installation
npm install aylien-news-api
Import and initiate the SDK
var AylienNewsApi = require("aylien-news-api");
var defaultClient = AylienNewsApi.ApiClient.instance;
var app_id = defaultClient.authentications["app_id"];
app_id.apiKey = process.env["NEWSAPI_APP_ID"];
var app_key = defaultClient.authentications["app_key"];
app_key.apiKey = process.env["NEWSAPI_APP_KEY"];
var api = new AylienNewsApi.DefaultApi();
var opts = {
title: "trump",
sortBy: "social_shares_count.facebook",
notLanguage: ["en"],
publishedAtStart: "NOW-7DAYS",
publishedAtEnd: "NOW",
entitiesBodyLinksDbpedia: [
"http://dbpedia.org/resource/Donald_Trump",
"http://dbpedia.org/resource/Hillary_Rodham_Clinton"
]
};
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log("API called successfully. Returned data: ");
console.log("========================================");
for (var i = 0; i < data.stories.length; i++) {
console.log(data.stories[i].title + " / " + data.stories[i].source.name);
}
}
};
api.listStories(opts, callback);
Installation
pip install aylien_news_api
Import and initiate the SDK
from __future__ import print_function
import time
import aylien_news_api
from aylien_news_api.rest import ApiException
from pprint import pprint
configuration = aylien_news_api.Configuration()
configuration.api_key['X-AYLIEN-NewsAPI-Application-ID'] = os.environ.get('NEWSAPI_APP_ID')
configuration.api_key['X-AYLIEN-NewsAPI-Application-Key'] = os.environ.get('NEWSAPI_APP_KEY')
client = aylien_news_api.ApiClient(configuration)
api_instance = aylien_news_api.DefaultApi(client)
try:
api_response = api_instance.list_stories(
title='startup',
published_at_start='NOW-7DAYS',
published_at_end='NOW',
not_language=['en']
)
pprint(api_response)
except ApiException as e:
print("Exception when calling DefaultApi->list_stories: %s\n" % e)
Installation
gem install aylien_news_api
Import and initiate the SDK
# Load the gem
require 'aylien_news_api'
# Setup authorization
AylienNewsApi.configure do |config|
config.api_key['X-AYLIEN-NewsAPI-Application-ID'] = ENV['NEWSAPI_APP_ID']
config.api_key['X-AYLIEN-NewsAPI-Application-Key'] = ENV['NEWSAPI_APP_KEY']
end
api_instance = AylienNewsApi::DefaultApi.new
opts = {
title: 'trump',
published_at_start: "NOW-7DAYS",
published_at_end: "NOW",
entities_body_links_dbpedia: [
'http://dbpedia.org/resource/Donald_Trump',
],
not_language: ['en'],
sort_by: 'social_shares_count.facebook'
}
begin
result = api_instance.list_stories(opts)
result.stories.each do |story|
puts "#{story.title} / #{story.source.name}"
end
rescue AylienNewsApi::ApiError => e
puts "Exception when calling DefaultApi->list_stories: #{e}"
puts e.response_body
end