Я нашел ответ:
создать токен обновления
$request_url = "https://www.googleapis.com/oauth2/v4/token";
$refresh_token = "*** Refresf Token ***";
$params = [
'client_id' => "***your client id***",
'client_secret' => "***your clinet secret id***",
'refresh_token' => $refresh_token,
'grant_type' => "refresh_token"
];
$curl = curl_init($request_url);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HEADER,'Content-Type: application/x-www-form-urlencoded');
$postData = "";
//This is needed to properly form post the credentials object
foreach($params as $k => $v) {
$postData .= $k . '='.urlencode($v).'&';
}
$postData = rtrim($postData, '&');
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
$json_response = curl_exec($curl);
$response = (array) json_decode( $json_response );
$myaccess_token = $response['access_token'];
И создать сообщение
$location = 'accounts/accoutid/locations/location id';
$api_end_point_url = 'https://mybusiness.googleapis.com/v4/'.$location.'/localPosts';
$postfields = array(
'topicType' => "STANDARD",
'languageCode' => "en_US",
'summary' => 'test post 123',
);
$data_string = json_encode($postfields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_end_point_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer '. $myaccess_token,'Content-Type: application/json'));
$data1 = json_decode(curl_exec($ch), true);
$http_code1 = curl_getinfo($ch, CURLINFO_HTTP_CODE);