1. Go to this page and download the library: Download napp/salesforce-api 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/ */
$sfClient = \Napp\Salesforce\Client::create('https://test.salesforce.com/', 'clientid', 'clientsecret');
$tokenGenerator = new \Napp\Salesforce\AccessTokenGenerator();
$accessToken = $tokenGenerator->createFromJson($_SESSION['accessToken']);
$sfClient->setAccessToken($accessToken);
$results = $sfClient->search('SELECT Name, Email FROM Lead Limit 10');
print_r($results);
class SalesforceConfig implements \Napp\Salesforce\ClientConfigInterface {
/**
* @return string
*/
public function getLoginUrl()
{
return 'https://test.salesforce.com/';
}
/**
* @return string
*/
public function getClientId()
{
return 'clientid';
}
/**
* @return string
*/
public function getClientSecret()
{
return 'clientsecret';
}
/**
* Version of the API you wish to use
* @return string
*/
public function getVersion()
{
return 'v37.0';
}
}
$sfConfig = new SalesforceConfig();
$sfClient = new \Napp\Salesforce\Client($sfConfig, new GuzzleHttp\Client());
$tokenGenerator = new \Napp\Salesforce\AccessTokenGenerator();
$accessToken = $tokenGenerator->createFromSalesforceResponse($token);
class SFLocalFileStoreConfig implements \Napp\Salesforce\TokenStore\LocalFileConfigInterface {
/**
* The path where the file will be stored, no trailing slash, must be writable
*
* @return string
*/
public function getFilePath()
{
return __DIR__;
}
}
$tokenStore = new \Napp\Salesforce\TokenStore\LocalFile(new \Napp\Salesforce\AccessTokenGenerator, new SFLocalFileStoreConfig);
//Save a token
$tokenStore->saveAccessToken($accessToken);
//Fetch a token
$accessToken = $tokenStore->fetchAccessToken();
$sfConfig = new SalesforceConfig();
$sfClient = new \Napp\Salesforce\Client($sfConfig, new \GuzzleHttp\Client());
$sfClient->setAccessToken($accessToken);
$data = $sfClient->search('SELECT Email, Name FROM Lead LIMIT 10');