News API SDKs | AYLIEN

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();

// Configure API key authorization: app_id
var app_id = apiInstance.apiClient.authentications['app_id'];
app_id.apiKey = "YOUR APP ID";

// Configure API key authorization: app_key
var app_key = apiInstance.apiClient.authentications['app_key'];
app_key.apiKey = "YOUR APP KEY";

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: ' + data);
}
};
apiInstance.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:

import aylien_news_api
from aylien_news_api.rest import ApiException

# Configure API key authorization: app_id
aylien_news_api.configuration.api_key['X-AYLIEN-NewsAPI-Application-ID'] = 'YOUR_APP_ID'
# Configure API key authorization: app_key
aylien_news_api.configuration.api_key['X-AYLIEN-NewsAPI-Application-Key'] = 'YOUR_APP_KEY'

# create an instance of the API class
api_instance = aylien_news_api.DefaultApi()

title = 'trump'
sort_by = 'social_shares_count.facebook'
language = ['en']
since = 'NOW-7DAYS'
until = 'NOW'
entities = [
    'http://dbpedia.org/resource/Donald_Trump',
    'http://dbpedia.org/resource/Hillary_Rodham_Clinton'
]

try:
# List stories
api_response = api_instance.list_stories(title=title, language=language, published_at_start=since, published_at_end=until, entities_body_links_dbpedia=entities, sort_by=sort_by)
print(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": "~1.0.0"
    }
}
                        

You can then import and initiate the SDK easily:

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

// Configure API key authorization: app_id
Aylien\NewsApi\Configuration::getDefaultConfiguration()->setApiKey('X-AYLIEN-NewsAPI-Application-ID', 'YOUR_APP_ID');

// Configure API key authorization: app_key
Aylien\NewsApi\Configuration::getDefaultConfiguration()->setApiKey('X-AYLIEN-NewsAPI-Application-Key', 'YOUR_APP_KEY');

$api_instance = new Aylien\NewsApi\Api\DefaultApi();

$opts = array(
    'title' => 'trump',
    'published_at_start' => 'NOW-7DAYS',
    'published_at_end' => 'NOW',
    'entities_body_links_dbpedia' => [
        'http://dbpedia.org/resource/Donald_Trump',
        'http://dbpedia.org/resource/Hillary_Rodham_Clinton'
    ],
    'language' => ['en'],
    'sort_by' => 'social_shares_count.facebook'
);

try {
    $result = $api_instance->listStories($opts);;
        print_r($result);
} catch (Exception $e) {
    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|
# Configure API key authorization: app_id
config.api_key['X-AYLIEN-NewsAPI-Application-ID'] = 'YOUR APP ID'

# Configure API key authorization: app_key
config.api_key['X-AYLIEN-NewsAPI-Application-Key'] = 'YOUR 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',
        'http://dbpedia.org/resource/Hillary_Rodham_Clinton'
    ],
    :language => ['en'],
    :sort_by => 'social_shares_count.facebook'
}

begin
#List stories
result = api_instance.list_stories(opts)
puts result
rescue AylienNewsApi::ApiError => e
puts "Exception when calling DefaultApi->list_stories: #{e}"
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>0.0.1<‌/version>
<‌scope>compile<‌/scope>
<‌/‌dependency>
                        

And for SBT users:

"com.aylien.newsapi" % "client" % "0.0.1"
                        

Example:

package com.aylien.newsapisample;

import com.aylien.newsapi.*;
import com.aylien.newsapi.auth.*;
import com.aylien.newsapi.models.*;
import com.aylien.newsapi.parameters.*;
import com.aylien.newsapi.api.DefaultApi;

import java.util.*;

public class Main {

    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();

        // Configure API key authorization: app_id
        ApiKeyAuth app_id = (ApiKeyAuth) defaultClient.getAuthentication("app_id");
        app_id.setApiKey("YOUR APP ID");

        // Configure API key authorization: app_key
        ApiKeyAuth app_key = (ApiKeyAuth) defaultClient.getAuthentication("app_key");
        app_key.setApiKey("YOUR APP KEY");

        DefaultApi apiInstance = new DefaultApi();

        StoriesParams.Builder storiesBuilder = StoriesParams.newBuilder();

        String title = "trump";
        String sortBy = "social_shares_count.facebook";
        List language = new ArrayList() {{
            add("en");
        }};
        String since = "NOW-7DAYS";
        String until = "NOW";
        List entities = new ArrayList() {{
            add("http://dbpedia.org/resource/Donald_Trump");
            add("http://dbpedia.org/resource/Hillary_Rodham_Clinton");
        }};

        storiesBuilder.setTitle(title);
        storiesBuilder.setSortBy(sortBy);
        storiesBuilder.setLanguage(language);
        storiesBuilder.setPublishedAtStart(since);
        storiesBuilder.setPublishedAtEnd(until);
        storiesBuilder.setEntitiesBodyLinksDbpedia(entities);

        try {
            Stories result = apiInstance.listStories(storiesBuilder.build());
            System.out.println(result);
        } 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 (
    "fmt"
    newsapi "github.com/AYLIEN/aylien_newsapi_go"
)

func main() {
    api := newsapi.NewDefaultApi()

    // Configure API key authorization: app_id
    api.Configuration.APIKeyPrefix["X-AYLIEN-NewsAPI-Application-ID"] = "YOUR APP ID"

    // Configure API key authorization: app_key
    api.Configuration.APIKeyPrefix["X-AYLIEN-NewsAPI-Application-Key"] = "YOUR APP KEY"

    title := "trump"
    until := "NOW"
    since := "NOW-7DAYS"
    sortBy := "social_shares_count.facebook"
    language := []string{"en"}
    entities := []string{
        "http://dbpedia.org/resource/Donald_Trump",
        "http://dbpedia.org/resource/Hillary_Rodham_Clinton",
    }

    storiesParams := &newsapi.StoriesParams{
        Title:                    title,
        Language:                 language,
        PublishedAtStart:         since,
        PublishedAtEnd:           until,
        EntitiesBodyLinksDbpedia: entities,
        SortBy: sortBy}

    storiesResponse, res, err := api.ListStories(storiesParams)
    if err != nil {
        panic(err)
    }
    _ = res

    fmt.Println(storiesResponse)
}
                        

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 System.Diagnostics;
using Aylien.NewsApi.Api;
using Aylien.NewsApi.Client;
using Aylien.NewsApi.Model;
using System.Collections.Generic;

namespace Example
{
    public class Example
    {
        static void Main(string[] args)
        {

            // Configure API key authorization: app_id
            Configuration.Default.ApiKey.Add("X-AYLIEN-NewsAPI-Application-ID", "YOUR_APP_ID");

            // Configure API key authorization: app_key
            Configuration.Default.ApiKey.Add("X-AYLIEN-NewsAPI-Application-Key", "YOUR_APP_KEY");

            var apiInstance = new DefaultApi();

            string title = "trump";
            string since = "NOW-7DAYS";
            string until = "NOW";
            string sortBy = "social_shares_count.facebook";
            List<‌String> language = new List<‌String> { "en" };
            List<‌String> entities = new List<‌String> {
                "http://dbpedia.org/resource/Donald_Trump",
                "http://dbpedia.org/resource/Hillary_Rodham_Clinton"
            };

            try
            {
                // List stories
                Stories result = apiInstance.ListStories(title: title, publishedAtStart: since, publishedAtEnd: until, language: language, entitiesBodyLinksDbpedia: entities, sortBy: sortBy);
                Debug.WriteLine(result);
            }
            catch (Exception e)
            {
                Debug.Print("Exception when calling DefaultApi.ListStories: " + e.Message );
            }
        }
    }
}