Reputation: 1
what would be the best way to get data into html/php to display them in browser. All data is from Invision Power board Rest API. - https://invisioncommunity.com/developers/rest-api
How can I display them? Example: I need only all usernames and 5 latest topics from specific category.
In endpoint I only get out one of them.
<?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 );
Upvotes: -2
Views: 2224
Reputation: 95
That's the way to achieve that. Keep in mind that '2' is the forum ID that you want to get the posts displayed. You can read more at the documentation of the API but the example i gave you will work like a charm.
$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';
}
Upvotes: 0