emergentmethods/asknews-php-sdk

0.2.16 2024-09-22 11:33 UTC

This package is auto-updated.

Last update: 2024-09-22 11:34:04 UTC


README

AskNews API

安装与使用

要求

PHP 8.0 及更高版本。

Composer

要通过 Composer 安装绑定,请在 composer.json 中添加以下内容

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

然后运行 composer install

手动安装

下载文件并包含 autoload.php

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

入门指南

请按照 安装过程 进行操作,然后运行以下命令

<?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 端点

所有 URI 都相对于 https://api.asknews.app

模型

授权

  • 类型: OAuth
  • 流程: client_credentials
  • 授权 URL: https://auth.asknews.app/oauth2/auth
  • 作用域:
    • chat: 聊天相关操作
    • news: 新闻相关操作
    • analytics: 分析相关操作
    • stories: 故事相关操作
    • profile: 个人资料相关操作
    • reddit: Reddit 相关操作
    • forecast: 预测相关操作

AskNews API 文档 中查找完整详情。

支持

加入我们的Discord,查看其他人正在构建的内容,并获得您项目支持。