Kasus praktis tentang cara mengembangkan skenario integrasi Anda sendiri
Layanan Google untuk bekerja dengan dokumen teks (Google Docs) dan spreadsheet (Google Sheets), yang muncul pada tahun 2006, dilengkapi 6 tahun kemudian dengan kemampuan bekerja dengan disk virtual (Google Drive), dan memenangkan cinta yang luas di antara pengguna, menghilangkan Microsoft dari monopoli selama puluhan tahun bekerja dengan perangkat lunak perkantoran.
, , , Google-, , . Google-.
Google- CRM-. , Β« Β» , CRM- , Google Drive , , . , Google- .
CRM- Google 24 .
, 24 amoCRM . , ?
, - Google β : REST API Google Script. , REST API Google , , create . , , , API .
, , . - , , , CRM-.
1.
, , ID .
script .
, , Javascript, Google.
2. Google Cloud Platform
, «» . Google Cloud Platform. Enable Google Script API : https://developers.google.com/apps-script/api/quickstart/php.
API, credentials.json, . .
3.
, .
, PHP-.
4. PHP-
API Google , : composer require google/apiclient:^2.0
:
function getClient()
{
$client = new Google_Client();
$client->setApplicationName('Google Apps Script API PHP Quickstart');
//
$client->setScopes("https://www.googleapis.com/auth/documents https://www.googleapis.com/auth/drive");
// credential.json, Google
$client->setAuthConfig('credentials.json');
$client->setAccessType('offline');
$client->setPrompt('select_account consent');
// token.json
$tokenPath = 'token.json';
if (file_exists($tokenPath)) {
$accessToken = json_decode(file_get_contents($tokenPath), true);
$client->setAccessToken($accessToken);
}
//
if ($client->isAccessTokenExpired()) {
if ($client->getRefreshToken()) {
$client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
} else {
$authUrl = $client->createAuthUrl();
printf("Open the following link in your browser:\n%s\n", $authUrl);
print 'Enter verification code: ';
$authCode = trim(fgets(STDIN));
$accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
print_r($accessToken);
$client->setAccessToken($accessToken);
if (array_key_exists('error', $accessToken)) {
throw new Exception(join(', ', $accessToken));
}
}
//
if (!file_exists(dirname($tokenPath))) {
mkdir(dirname($tokenPath), 0700, true);
}
file_put_contents($tokenPath, json_encode($client->getAccessToken()));
}
return $client;
}
ssh β βphp ( )β.
url, verification code url , 1, . (token.json), PHP-. , .
, , .
//
$client = getClient();
$service = new Google_Service_Script($client);
//
$scriptId = '***********************wKhTTdKL7ChremS5AkvzwlPJARnxqisW7TzDB ';
$request = new Google_Service_Script_ExecutionRequest();
//
$request->setFunction('FillTemplate');
$request->setParameters([$_REQUEST['customer'],$_REQUEST['link'],$_REQUEST['formsv'],$_REQUEST['socnet'],$_REQUEST['whatsi'], $_REQUEST['ats'],$_REQUEST['pipeline'],$_REQUEST['outscope'],$_REQUEST['editor'],$_REQUEST['viewer']]);
try {
// Make the API request.
$response = $service->scripts->run($scriptId, $request);
if ($response->getError()) {
//
$error = $response->getError()['details'][0];
printf("Script error message: %s\n", $error['errorMessage']);
if (array_key_exists('scriptStackTraceElements', $error)) {
print "Script error stacktrace:\n";
foreach($error['scriptStackTraceElements'] as $trace) {
printf("\t%s: %d\n", $trace['function'], $trace['lineNumber']);
}
}
}
} catch (Exception $e) {
//
echo 'Caught exception: ', $e->getMessage(), "\n";
}
5. PHP- CRM
, CRM.
CRM , . c :
, 24 -, Get- , -.
Google Drive:
URL, Get-. , 4 ( 2048 ).
Oleh karena itu, jika teks yang ditransfer ke dokumen cukup panjang, maka kami menyarankan pengguna Bitrix24 untuk menulis aktivasi proses bisnis mereka sendiri. Informasi tentang pendekatan perkembangannya dapat diambil dari artikel ini .