asknews-php-sdk

AskNews API

Installation & Usage

Requirements

PHP 8.0 and later.

Composer

To install the bindings via Composer, add the following to composer.json:

{
  "repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/emergentmethods/asknews-php-sdk.git"
    }
  ],
  "require": {
    "emergentmethods/asknews-php-sdk": "*@dev"
  }
}

Then run composer install

Manual Installation

Download the files and include autoload.php:

<?php
require_once('/path/to/asknews-php-sdk/vendor/autoload.php');

Getting Started

Please follow the installation procedure and then run the following:

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




// Configure sdk credentials
$config = new AskNews\Configuration([
  'clientId' => 'YOUR_ASKNEWS_CLIENT_ID',
  'clientSecret' => 'YOUR_ASKNEWS_CLIENT_SECRET',
  'scopes' => ['news', 'chat', 'stories', 'analytics']
]);


$apiInstance = new AskNews\Api\AnalyticsApi(
    // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
    // This is optional, `GuzzleHttp\Client` will be used as default.
    new GuzzleHttp\Client(),
    $config
);
$asset = 'asset_example'; // string | The asset name to query for sentiment.
$metric = 'news_positive'; // string | The metric to obtain. Weighted metrics account for page-rank of original source. Higher page rank sources are weighted more heavily.
$date_from = new \DateTime("2013-10-20T19:20:30+01:00"); // \DateTime | The start date in ISO format
$date_to = new \DateTime("2013-10-20T19:20:30+01:00"); // \DateTime | The end date in ISO format

try {
    $result = $apiInstance->getAssetSentiment($asset, $metric, $date_from, $date_to);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling AnalyticsApi->getAssetSentiment: ', $e->getMessage(), PHP_EOL;
}

API Endpoints

All URIs are relative to https://api.asknews.app

Class Method HTTP request Description
AnalyticsApi getAssetSentiment GET /v1/analytics/finance/sentiment Get a timeseries of finance news sentiment for assets
ChatApi getChatCompletions POST /v1/openai/chat/completions Get chat completions from a news-infused AI assistant
ChatApi getHeadlineQuestions GET /v1/chat/questions Get example headline questions
ChatApi listChatModels GET /v1/openai/models List available chat models
ForecastApi getForecast GET /v1/chat/forecast Make an expert forecast for a news event.
GraphApi buildGraph POST /v1/news/graph Build a custom mega-news-knowledge graph
NewsApi getArticle GET /v1/news/{article_id} Get an article by its UUID
NewsApi getSourcesReport GET /v1/sources Get the sources underlying AskNews
NewsApi searchNews GET /v1/news/search Search for enriched real-time news context
PingApi ping GET / Ping
RedditApi searchReddit GET /v1/reddit/search Search Reddit, summarize threads, and return analysis.
StoriesApi getStories GET /v1/stories Filter and search for top news narratives
StoriesApi getStory GET /v1/stories/{story_id} Get a story containing updates
WebsearchApi liveWebSearch GET /v1/chat/websearch Run a live websearch.

Models

Authorization

  • Type: OAuth
  • Flow: client_credentials
  • Authorization URL: https://auth.asknews.app/oauth2/auth
  • Scopes:
    • chat: Chat related operations
    • news: News related operations
    • analytics: Analytics related operations
    • stories: Stories related operations
    • profile: Profile related operations
    • reddit: Reddit related operations
    • forecast: Forecast related operations

Find full details at the AskNews API documentation.

Support

Join our Discord to see what other people are building, and to get support with your projects.