PHP code example of dldl / webservice

1. Go to this page and download the library: Download dldl/webservice 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/ */

    

dldl / webservice example snippets




namespace MyApp\WebService;

use dLdL\WebService\WebServiceInterface;
use dLdL\WebService\ConnectorInterface;
use dLdL\WebService\ParserInterface;
use dLdL\WebService\Exception\WebServiceException;
use dLdL\WebService\Http\Request;

class FacebookWebService implements WebServiceInterface
{
    private $connector;
    private $parser;
    private $host;

    public function __construct(ConnectorInterface $connector, ParserInterface $parser, $host)
    {
        $this->connector = $connector;
        $this->parser = $parser;
        $this->host = $host;
    }

    public function getConnector()
    {
        return $this->connector;
    }
    
    public function getPosts($facebookUsername)
    {
        try {
            $this->getConnector()->connect($this->host);
        } catch (WebServiceException $e) {
            return [];
        }
        
        $request = new Request($facebookUsername . '/feed');
        $this->getConnector()->getCache()->getConfig()->add($request, 60*60*24);
        
        try {
            $postData = $this->getConnector()->sendRequest($request);
        } catch (WebServiceException $e) {
            return [];
        }
        
        $this->getConnector()->disconnect();
        
        return $this->parser->parse($postData);
    }
}