Connect Wordpress with SharePoint

I'm new here and I'm also new to WordPress. I'm currently trying to connect my WP site to SharePoint and I'm stuck.

My approach to solve this was to search for php libraries that would help me with this connection. I found this two:

PHP-SharePoint-Lists-API

phpSPO

The last one seems better but I'm having a problem to use classes in php files after installing dependencies with Composer in the theme I created.

require_once __DIR__ . '/vendor/autoload.php';

use Office365\Runtime\Auth\ClientCredential;
use Office365\SharePoint\ClientContext;
use Office365\SharePoint\ListItem; 

$credentials = new ClientCredential({client-id}, {client-secret});
$client = (new ClientContext({sharepoint_url}))-withCredentials($credentials);

$web = $client-getWeb();
$list = $web-getLists()-getByTitle({list-id}); //init List resource
$items = $list-getItems();  //prepare a query to retrieve from the 
$client-load($items);  //save a query to retrieve list items from the server 
$client-executeQuery(); //submit query to SharePoint Online REST service
/** @var ListItem $item */
// echo ITEMS: $items;
foreach($items as $item) {
    print Task: {$item-getProperty('Title')}\r\n;
}

In the code above I'm getting erros when I do new ClientCredencital(....) and new ClientContext(...)

What I pretend to know is:

  1. Why am I getting this errors while using classes from the library installed?
  2. Is this the best way to connect WP to SharePoint? If no, can you tell me the best one?

Sorry if I'm not clear enough. You can ask everything you want :)

Thanks for the help!

Topic autoloading php themes Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.