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";
Related
I have a this folder structure:
+ inc
++ functions.php
++ vendor
+ private
++ carddav
+++ check.php
my check.php looks like this and works:
<?php
require '../../inc/functions.php';
// CardDAV API
require '../../inc/vendor/autoload.php';
use MStilkerich\CardDavClient\{Account, AddressbookCollection, Config};
use Psr\Log\{AbstractLogger, NullLogger, LogLevel};
use Sabre\VObject\Component\VCard;
class StdoutLogger extends AbstractLogger {
public function log($level, $message, array $context = array()) {
if ($level !== LogLevel::DEBUG) {
$ctx = empty($context) ? "" : json_encode($context);
echo ">>> ".$message . $ctx . "<br />";
}
}
}
Config::init(new StdoutLogger());
$account = new Account(URL, USERNAME, PASSWORD);
$abook = new AddressbookCollection(URL, $account);
$vcard = new VCard();
?>
But now I would like to outsource this part into my functions.php:
functions.php
<?
// CardDAV API
require 'vendor/autoload.php';
use MStilkerich\CardDavClient\{Account, AddressbookCollection, Config};
use Psr\Log\{AbstractLogger, NullLogger, LogLevel};
use Sabre\VObject\Component\VCard;
class StdoutLogger extends AbstractLogger {
public function log($level, $message, array $context = array()) {
if ($level !== LogLevel::DEBUG) {
$ctx = empty($context) ? "" : json_encode($context);
echo ">>> ".$message . $ctx . "<br />";
}
}
}
Config::init(new StdoutLogger());
$account = new Account(URL, USERNAME, PASSWORD);
$abook = new AddressbookCollection(URL, $account);
?>
check.php
<?php
require '../../inc/functions.php';
$vcard = new VCard();
?>
But now I get this error when I open the check.php:
Fatal error: Uncaught Error: Class 'VCard' not found in check.php:26
Where is my mistake?
Tank you !
Imports using use statement work on a per file basis. I.e. classes need to be imported in the file where they're used. In your case remove Sabre\VObject\Component\VCard import from functions.php and move it to check.php where VCard class is actually used.
the path also correct but i still don't know why it shows class not found as a fatal error
<?php
ini_set('display_errors', 1);
require_once('../core/Http/Response.php');
use core\Http;
if(class_exists("Response")){
echo "ok";
}
else {
echo "doesn't exist";
}
$r = new Response();
$r->header('test');
?>
normal call in php file,
<?php
ini_set('display_errors', 1);
require_once('../core/Http/Response.php');
use Core\Http\Response;
if(class_exists( 'Core\Http\Response' )){
$r = new Response(); // -OR- $r = new Core\Http\Response();
}else{
die('class doesn\'t exist');
}
$r->header('test');
?>
If you want to call in any controller, call like following
<?php
// Start of the file
ini_set('display_errors', 1);
require_once('../core/Http/Response.php');
use Core\Http\Response;
// your class
class Test extends Test_Controller {
public function test(){
if(class_exists( 'Core\Http\Response' )){
$r = new Response(); // -OR- $r = new Core\Http\Response();
}else{
die('class doesn\'t exist');
}
$r->header('test');
}
}
?>
<?php
ini_set('display_errors', 1);
require_once dirname(__DIR__) . '/Core/Http/Response.php';
use \Core\Http\Response;
$test = new Response("test response");
echo $test ;
?>
I'm fairly new to the Slim framework and I'm getting an error in a very basic call $request->get.
provision/hosts - OK
provision/hosts/28E34748B48E - OK
provision/hosts/search?hostname=ACACA - NOK
Although var_dump($_GET) returns:
array(1) {
["hostname"]=>
string(5) "ACACA"
}
Contents of the index.php file:
<?php
require 'vendor/autoload.php';
//With default settings
$app = new \Slim\App;
$app->get('/hosts', function ($request,$response,$args) {
require_once 'db.php';
$query= "SELECT * FROM hosts";
$result = $mysqli->query($query);
while($row=$result->fetch_assoc()) {
$data[]=$row;
}
if(isset($data)) {
header('Content-Type: application/json');
echo json_encode($data);
}
});
$app->get('/hosts/search', function ($request,$response,$args) {
require_once 'db.php';
//echo var_dump($_GET);
$hostname=$request->get('hostname');
echo $hostname;
});
$app->get('/hosts/{macaddr}', function ($request,$response,$args) {
require_once 'db.php';
$query= "SELECT * FROM hosts WHERE macaddr='".$args['macaddr']."'";
$result = $mysqli->query($query);
$data=$result->fetch_assoc();
if(isset($data)) {
header('Content-Type: application/json');
echo json_encode($data);
}
});
$app->run();
?>
The method get doesn't exist in Slim\Http\Request
Fatal error: Call to undefined method Slim\Http\Request::get() in /slim3/index.php on line
You need to use getParam
$hostname = $request->getParam('hostname');
session_start();
date_default_timezone_set('GMT');
require 'Slim/Slim.php';
use Slim\Slim;
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
require_once 'item.php';
this is code excerpt from index.php and stuck on the said error when it called item.php. Here the contains of the file
$app->put('/getItem', authorize(), 'getItem');
function getItem() {
$sql = "SELECT * FROM item";
$app = Slim::getInstance();
try {
$db = getConnection();
$stmt = $db->query($sql);
$item = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
$response = $app->response();
$response->header('Content-Type', 'application/json');
// Include support for JSONP requests
if (!isset($_GET['callback'])) {
echo json_encode($item);
} else {
echo $_GET['callback'] . '(' . json_encode($item) . ');';
}
} catch(PDOException $e) {
$error = array("error"=> array("text"=>$e->getMessage()));
echo json_encode($error);
}
}
i hit the error on this $app = Slim::getInstance();
What is wrong with my approach?
The Slim class' full name (including namespace) is \Slim\Slim so you'll need to use that, eg
$app = \Slim\Slim::getInstance();
Alternatively, you can import the Slim symbol using the use statement at the top of your item.php script.
use Slim\Slim;
You can use this code for Slim Framework3:
<?php
require "vendor/autoload.php";
use \Slim\App;
$app = new App();
$app->get("/",function(){
echo "Hello World";
});
$app->get("/test",function(){
echo "Hello World";
});
$app->run();
?>
we moved our website to a new server that came with a new IP address. What puzzles me; the website login sessions do not work on the new server but when I change the database IP to the old server they are working.
MySQL Version :
Old server = 5.1.58- Community
New server = 5.1.68 - Community
At first I thought it was a PHP error but I now believe it's not and suspect its MySQL related. Anyone who knows what might have caused this conflict?
Debugging Error :
Notice: A session had already been started - ignoring session_start() in C:\inetpub\wwwroot\gtest\libs\products.php on line 2 Notice: Undefined index: uUserTypeID in C:\inetpub\wwwroot\gtest\admin\index.php on line 50 Notice: Undefined offset: 0 in C:\inetpub\wwwroot\gtest\admin\index.php on line 52 Notice: Undefined offset: 0 in C:\inetpub\wwwroot\gtest\admin\index.php on line 52
Line 50 :
GetUserType($_SESSION['uUserTypeID'], $UserTypeID, $UserTypeDescr, $Active_Tag);
Line 52 :
if (($UserTypeDescr[0] == 'Admin') || ($UserTypeDescr[0] == 'Report'))
Code overview :
<?php
error_reporting(E_ALL);
ini_set('display_errors', True);
session_start();
require '../libs/database.php';
require '../libs/users.php';
require '../libs/products.php';
require '../libs/quotes.php';
require '../libs/common.php';
require 'functions.admin.php';
if (!($_SESSION['uAUID']) > 0)
{
DisplayLoginForm();
}
else
{
**GetUserType($_SESSION['uUserTypeID'], $UserTypeID, $UserTypeDescr, $Active_Tag);**
**if (($UserTypeDescr[0] == 'Admin') || ($UserTypeDescr[0] == 'Report'))**
{
if (isset($_POST['eProdID']) && isset($_POST['eProdGroupID']))
{
$_SESSION['page'] = 'edit_product';
$_SESSION['page_header'] = 'Edit Product';
}
else if (isset($_POST['eProdGroupID']))
{
$_SESSION['page'] = 'edit_product_group';
$_SESSION['page_header'] = 'Edit Product Group';
}
else if (isset($_POST['eAUID']))
{
$_SESSION['page'] = 'edit_user';
$_SESSION['page_header'] = 'Edit User';
Check over your included files/code structure.. A usual cause for this error is:
session_start();
/* Random Code here /*
session_start();
Just the duplicate lines of session_start(); So what I will suggest is to look over your included files/main page(s) that you are receiving this error message on, and check for more than one session_start();