1. Go to this page and download the library: Download vpmv/marketo-client 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/ */
vpmv / marketo-client example snippets
namespace App;
use VPMV\Marketo\Oauth\AccessToken;
use VPMV\Marketo\MarketoClient;
class DemoMarketoAPI extends Marketo
{
public function __cosntruct() {
parent::__construct($this->getMarketoClient());
}
public function getMarketoClient():MarketoClient
{
if (empty($this->client)) {
$this->client = MarketoClient::with(
'CLIENT_ID',
'CLIENT_SECRET',
'BASE_URL',
$this->getRefreshTokenFromCache(),
$this->tokenRefreshCallback
);
}
return $this->client;
}
private function getRefreshTokenFromCache(): ?AccessToken {
// get token from cache
return new AccessToken('my_token', 300, 1642768705);
// or return null
}
public function tokenRefreshCallback(AccessToken $token)
{
// store the token
}
}
$demoMarketo = new DemoMarketoAPI();
$options = [
"programName" => "My Marketo Program",
"batchSize" => 10
];
$campaigns = $demoMarketo->campaigns()->getCampaigns($options);
// getCampaigns() can also be called without options.
// $campaigns = { ... }