News API SDKs

To make things as easy as possible, we have a number of SDKs you can import into your development environment to get up and running quickly.

Looking to integrate with AYLIEN News API?
Our SDKs are built on the AYLIEN News API and are the easiest and quickest way to bring the power of the News API to your App or solution.
Install AYLIEN News API SDKs

With our documentation and SDKs you’ll be up and running in minutes

Visit our GitHub page to download our Node.js SDK repo, or you can run an example with the code below:

Installation:

$ npm install aylien-news-api --save
                        

You can then import and initiate the SDK easily:

var AylienNewsApi = require('aylien-news-api');

var apiInstance = new AylienNewsApi.DefaultApi() 
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',
    'language': ['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);
                        

Visit our GitHub page to download our Python SDK repo, or you can run an example with the code below:

Installation:

$ pip install aylien_news_api
                        

You can then import and initiate the SDK easily:

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)
                        

Visit our GitHub page to download our PHP SDK repo, or you can run an example with the code below:

Installation:

Simply add the following to your composer.json:

{
    "require": {
        "aylien/newsapi": "3.0.0"
    }
}
                        

You can then import and initiate the SDK easily:


require_once(__DIR__ . '/vendor/autoload.php');

// Configure API key authorization: app_id
$config = Aylien\NewsApi\Configuration::getDefaultConfiguration()->setApiKey('X-AYLIEN-NewsAPI-Application-ID', $_SERVER['NEWSAPI_APP_ID']);

// Configure API key authorization: app_key
$config = Aylien\NewsApi\Configuration::getDefaultConfiguration()->setApiKey('X-AYLIEN-NewsAPI-Application-Key', $_SERVER['NEWSAPI_APP_KEY']);

$apiInstance = new Aylien\NewsApi\Api\DefaultApi(
    new GuzzleHttp\Client(),
    $config
);

$opts = array(
  'title' => 'trump',
  'publishedAtStart' => 'NOW-7DAYS',
  'publishedAtEnd' => 'NOW',
  'entitiesBodyLinksDbpedia' => [
    'http://dbpedia.org/resource/Donald_Trump',
    'http://dbpedia.org/resource/Hillary_Rodham_Clinton'
  ],
  'notLanguage' => ['en'],
  'sortBy' => 'social_shares_count.facebook'
);

try {
    $result = $apiInstance->listStories($opts);
    for($i = 0; $i < sizeof($result->getStories()); $i++){
      print_r($result->getStories()[$i]->getTitle() . " / " .
        $result->getStories()[$i]->getSource()->getName() . "\n");
    }
} catch (Exception $e) {
    print_r($e->getResponseObject()->getErrors());
    echo 'Exception when calling DefaultApi->listStories: ', $e->getMessage(), "\n";
}

                        

Visit our GitHub page to download our Ruby SDK repo, or you can run an example with the code below:

Installation:

$ gem install 'aylien_news_api'
                        

You can then import and initiate the SDK easily:

# 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
                        

Visit our GitHub page to download our Java SDK repo, or you can run an example with the code below:

Installation:

Building the API client library requires Maven to be installed.

<dependency>
    <groupId>com.aylien.newsapi</groupId>
    <artifactId>client</artifactId>
    <version>3.0.0</version>
    <scope>compile</scope>
</‌dependency>
                        

Gradle users

Add this dependency to your project's build file:

compile "com.aylien.newsapi:client:3.0.0"
                        

And for SBT users:

Add this dependency to your libraryDependencies:

"com.aylien.newsapi" % "client" % "3.0.0"
                        

Example:

import com.aylien.newsapi.ApiClient;
import com.aylien.newsapi.ApiException;
import com.aylien.newsapi.Configuration;
import com.aylien.newsapi.api.DefaultApi;
import com.aylien.newsapi.auth.*;
import com.aylien.newsapi.models.*;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    ApiClient defaultClient = Configuration.getDefaultApiClient();
    defaultClient.setBasePath("https://api.aylien.com/news");

    // Configure API key authorization: app_id
    ApiKeyAuth app_id = (ApiKeyAuth)defaultClient.getAuthentication("app_id");
    app_id.setApiKey(System.getenv("NEWSAPI_APP_ID"));

    // Configure API key authorization: app_key
    ApiKeyAuth app_key = (ApiKeyAuth)defaultClient.getAuthentication("app_key");
    app_key.setApiKey(System.getenv("NEWSAPI_APP_KEY"));

    DefaultApi apiInstance = new DefaultApi(defaultClient);

    String title = "startup";
    String publishedAtStart = "NOW-3MONTHS";
    String publishedAtEnd = "NOW";
    Integer perPage = 10;

    try {
      Stories result = apiInstance.listStories()
                           .title(title)
                           .publishedAtStart(publishedAtStart)
                           .publishedAtEnd(publishedAtEnd)
                           .perPage(perPage)
                           .execute();
      for (Iterator i = result.getStories().iterator(); i.hasNext();) {
        Story story = (Story)i.next();
        System.out.println(story.getTitle() + " / " +
                           story.getSource().getName());
      }
    } catch (ApiException e) {
      System.err.println("Exception when calling DefaultApi#listStories");
      e.printStackTrace();
    }
  }
}
                        

Visit our GitHub page to download our Go SDK repo, or you can run an example with the code below:

Installation:

$ go get github.com/AYLIEN/aylien_newsapi_go
                        

You can then import and initiate the SDK easily:

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)
    }
}
                        

Visit our GitHub page to download our C# SDK repo, or you can run an example with the code below:

Installation:

The easiest way to get the C# SDK is to use NuGet.

PM> Install-Package Aylien.NewsApi
                        

You can then import and initiate the SDK easily:

using System;
using Aylien.NewsApi.Api;
using Aylien.NewsApi.Client;
using Aylien.NewsApi.Model;
using System.Collections.Generic;

namespace GettingStartedExample
{
    class Program
    {
        static void Main(string[] args)
        {
            // Configure API key authorization: app_id
            var apiId = System.Environment.GetEnvironmentVariable("X-AYLIEN-NewsAPI-Application-ID");
            Configuration.Default.ApiKey.Add("X-AYLIEN-NewsAPI-Application-ID", apiId);

            // Configure API key authorization: app_key
            var apiKey = System.Environment.GetEnvironmentVariable("X-AYLIEN-NewsAPI-Application-Key");
            Configuration.Default.ApiKey.Add("X-AYLIEN-NewsAPI-Application-Key", apiKey);

            var apiInstance = new DefaultApi();

            try
            {
                // List stories
                Stories storiesResponse = apiInstance.ListStories(
                    title: "trump",
                    publishedAtStart: "NOW-7DAYS",
                    publishedAtEnd: "NOW",
  
                    sortBy: "social_shares_count.facebook"
                );

                foreach (var story in storiesResponse._Stories)
                {
                    Console.WriteLine(story.Title + " / " + story.Source.Name);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception when calling DefaultApi.ListStories: " + e.Message);
            }
        }
    }
}