i am new to gmb and i am trying to learn from trying and i don't know if this is the right approach to get data, i am trying to get data data from gmb but i am getting 500 error
<?php
include_once '../../google-api-php-client-2.4.0/vendor/autoload.php'; // or wherever autoload.php is located
include_once './MyBusiness.php';
ini_set('max_execution_time', '0');
include_once "../../includes/config.php";
$client = new Google_Client();
if (isset($_SERVER['HTTP_HOST']) && ($_SERVER['HTTP_HOST'] == "localhost")) {
$client->setAuthConfig('../client_secret_for_Google_my_bussniss.json');
$json = json_decode(file_get_contents('../Google-My-Business-tokens.json'));
}else{
$client->setAuthConfig('/home/eblatech/insights-secrets/client_secret_for_Google_my_bussniss.json');
$json = json_decode(file_get_contents('/home/eblatech/insights-secrets/Google-My-Business-tokens.json'));
}
$client->addScope('https://www.googleapis.com/auth/business.manage');
$refreshToken = $json->refreshToken;
$_SESSION['access_token']=$json->access_token;
// echo '<pre>'; print_r($refreshToken); echo '</pre>';exit;
if (isset($refreshToken) && $refreshToken) {
$client->refreshToken($refreshToken);
$mybusinessService = new Google_Service_Mybusiness($client);
$posts = $mybusinessService->accounts_locations_localPosts;
$x=$posts->get("BlackSwanLimos");
echo '<pre>'; print_r($x); echo '</pre>';
update: i just opened error log and found this
19-Dec-2022 23:39:03 UTC] PHP Fatal error: Uncaught Google_Service_Exception
[20-Dec-2022 00:00:02 UTC] PHP Notice: Undefined index: HTTP_HOST in /home/eblatech/insights.ebla-tech.com/admin/includes/config.php on line 9
[20-Dec-2022 00:00:02 UTC] PHP Notice: Undefined index: REQUEST_URI in /home/eblatech/insights.ebla-tech.com/admin/includes/config.php on line 9
that is the config.php
<?php
session_set_cookie_params(2*3600,"/");
session_start();
$APP_ROOT = "/insights-dashboard/admin/";
$FILES_ROOT = "/insights-dashboard/admin/files/";
$MODEL_ROOT = realpath(dirname(__FILE__) . '/../../');
$actual_link = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
define("SESSION", "insightEbla");
define("DEFAULT_LANGUAGE", "en");
// var_dump($_SESSION);
// exit;
if (!isset($_SESSION[SESSION]['lang']) || empty($_SESSION[SESSION]['lang'])) {
$_SESSION[SESSION]['lang'] = DEFAULT_LANGUAGE;
};
$current_lang = $_SESSION[SESSION]['lang'];
if ($_SESSION[SESSION]['lang'] == 'ar') {
require_once "lang/ar.php";
} else {
require_once "lang/en.php";
}
require_once "page_names.php";
require_once "enum.php";
require_once $MODEL_ROOT . '/model/db_endpoint.php';
require_once "authentication.php";
require_once "functions.php";
require_once "authorization.php";
require_once "pages_includes.php";