useApplicationDefaultCredentials(); $client->addScope('https://www.googleapis.com/auth/firebase.messaging'); $httpClient = $client->authorize(); $hostname = 'localhost'; $username = 'narKampen'; $pass = 'IfRLzj2HJBXA9eei'; $database = 'narKampen'; $conn = new mysqli($hostname, $username, $pass, $database); if (!$conn) { die("Connection Failed. ". mysqli_connect_error()); } mysqli_set_charset($conn,'utf8'); $gameId = $conn->real_escape_string($_POST['gameId']); $playerName = $conn->real_escape_string($_POST['playerName']); $title = $conn->real_escape_string($_POST['title']); $message = $conn->real_escape_string($_POST['message']); $sql = "SELECT messageToken FROM `gamePlayers` INNER JOIN users ON users.id = playerId WHERE gameId = $gameId and users.username = '$playerName'"; $result = $conn->query($sql); if ($result->num_rows == 1) { $returnArray = array(); $data = $result->fetch_assoc(); $token = $data['messageToken']; } else { echo "No games found for user"; } if ($token != null && $token != "") { // Your Firebase project ID $project = "narkampen"; // Creates a notification for subscribers to the debug topic $message = [ "message" => [ "token" => $token, "notification" => [ "body" => $message, "title" => $title, ] ] ]; // Send the Push Notification - use $response to inspect success or errors $response = $httpClient->post("https://fcm.googleapis.com/v1/projects/{$project}/messages:send", ['json' => $message]); }