1. Go to this page and download the library: Download m6web/restconnection library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
m6web / restconnection example snippets
// Initialize the header of our future requests, specifying the format we want to use in request and response (json)
$requestHeader = array('Accept: application/json', 'Content-Type: application/json');
// Create the Client object, for now, no credential needed as we get only public tweets
$testAPI = new RESTConnection\Client('https://api.twitter.com/1/', $requestHeader);
// Issue a GET request on 'https://api.twitter.com/1/statuses/public_timeline.json'
if($testAPI->request('statuses/public_timeline.json'))
{
// Display the tweets
var_dump(json_decode($testAPI->getResponseBody(), true));
}
else
{
// Something went wrong
var_dump($testAPI->getLastError());
}
// Initialize the header of our future requests, specifying the format we want to use in request and response (json)
$requestHeader = array('Accept: application/json', 'Content-Type: application/json');
// Create the Client object, this time, credential are specified
$testAPI = new RESTConnection\Client('https://your.campfirenow.com/', $requestHeader, 'your_token_here', 'X');
// Issue a POST request on 'https://your.campfirenow.com/room/your_room_id/speak.json'
if($testAPI->request('room/your_room_id/speak.json', json_encode(array('message' => array('body' => "Hello"))), RESTConnection\Client::POST)))
{
// lastStatusCode should be 201
var_dump($testAPI->getLastStatusCode());
// Response body contains the message id
$result = (json_decode($testAPI->getResponseBody(), true));
// star the message
$messageid = $result['message']['id'];
$testAPI->request(sprintf('messages/%s/star.json', $messageid), array(), RESTConnection\Client::POST);
// unstar it
// $testAPI->request(sprintf('messages/%s/star.json', $messageid), array(), RESTConnection\Client::DELETE);
}
else
{
// Something went wrong
var_dump($testAPI->getLastError());
}
// Issue a PUT request on 'https://your.campfirenow.com/room/your_room_id.json'
$testAPI->request('room/your_room_id.json', json_encode(array('room' => array('topic' => "this room is not about cats"))), RESTConnection\Client::PUT);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.