【问题标题】:How to fetch and display data from Invision Power board Rest API如何从 Invision Power board Rest API 获取和显示数据
【发布时间】:2019-09-13 11:04:50
【问题描述】:

将数据导入 html/php 以在浏览器中显示它们的最佳方式是什么。所有数据均来自 Invision Power board Rest API。 - https://invisioncommunity.com/developers/rest-api

如何显示它们? 示例:我只需要特定类别的所有用户名和 5 个最新主题。

在端点我只取出其中一个。

<?php
$communityUrl = 'https://www.example.com/ips4/';
$apiKey = 'c7a349a1629f02cd2855a58d77646f6d';
$endpoint = '/core/hello';
$endpoint = '/core/members';

$curl = curl_init( $communityUrl . 'api' . $endpoint );
curl_setopt_array( $curl, array(
    CURLOPT_RETURNTRANSFER  => TRUE,
    CURLOPT_HTTPAUTH    => CURLAUTH_BASIC,
    CURLOPT_USERPWD     => "{$apiKey}:"
) );
$response = curl_exec( $curl );

【问题讨论】:

  • $response 变量里面有什么? print_r() 看看你收集了什么。
  • 使用 $response 我从一个 $endpoint 获取所有数据但我的问题是 - 如何从该端点获取特定数据。
  • 嗯,嗯...响应取决于您调用的端点和您传递的参数。所以你必须对这个API做一些研究......

标签: php json rest api invision-power-board


【解决方案1】:

这就是实现这一目标的方法。请记住,“2”是您希望显示帖子的论坛 ID。您可以在 API 的documentation 上阅读更多内容,但我给您的示例将非常有用。

$apiKey = 'YOUR_API_KEY';
$curl = curl_init('https://www.YOURSITE.com/community/api/index.php?/forums/topics&forums=2&sortDir=desc');

curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => TRUE,
    CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
    CURLOPT_USERPWD => "{$apiKey}:"
));
$response = curl_exec($curl);

$obj = json_decode($response);

if (isset($obj->results)) {
    return $obj->results;
} else {
    return 'error';
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-30
    • 2021-05-03
    • 1970-01-01
    相关资源
    最近更新 更多