How to connecting firebase from php? - php

Hello i am trying to make connection to firebase database from php and i have this code
<?php
require __DIR__.'/vendor/autoload.php';
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;
$serviceAccount = ServiceAccount::fromJsonFile(__DIR__ . '/secret/sajilo-entrance-med-firebase-adminsdk-1bta4-487ebfe276.json');
$factory = (new Factory)->withServiceAccount($serviceAccount);
$firebase = (new Factory)
->withServiceAccount('$serviceAccount')
->withDatabaseUri('https://sajilo-entrance-med.firebaseio.com/')
->create();
$database = $firebase->getDatabase();
?>
and i am getting this error
Fatal error: Uncaught TypeError: Argument 1 passed to Kreait\Firebase\Factory::withServiceAccount() must be an instance of Kreait\Firebase\ServiceAccount, string given, called in C:\xampp\htdocs\MedEntrance\dbconfig.php on line 10 and defined in C:\xampp\htdocs\MedEntrance\vendor\kreait\firebase-php\src\Firebase\Factory.php:77 Stack trace: #0 C:\xampp\htdocs\MedEntrance\dbconfig.php(10): Kreait\Firebase\Factory->withServiceAccount('$serviceAccount') #1 C:\xampp\htdocs\MedEntrance\insert_test.php(43): include('C:\xampp\htdocs...') #2 {main} thrown in C:\xampp\htdocs\MedEntrance\vendor\kreait\firebase-php\src\Firebase\Factory.php on line 77

Try change withServiceAccount('$serviceAccount') to withServiceAccount($serviceAccount)

Related

Submitting GetUserOofSettings and SetUserOofSettings request

Does anyone have any code about both getting and setting users OOF messages using Garethp/php-ews library by any chance?
(https://learn.microsoft.com/en-us/previous-versions/office/developer/exchange-server-2010/aa563465(v=exchg.140))
(https://learn.microsoft.com/en-us/previous-versions/office/developer/exchange-server-2010/aa493825(v=exchg.140))
I have tried the following
use garethp\ews\API\Type;
use garethp\ews\MailAPI;
use garethp\ews\API\Enumeration\DistinguishedFolderIdNameType;
use garethp\ews\API\Enumeration\UserConfigurationPropertyType;
use garethp\ews\API\Enumeration\GetUserOofSettingsRequestType;
$email = 'me#mycompany.com';
$host = 'myexchserver'; $username = 'myusername'; $password = 'mypassword';
$api = MailAPI::withUsernameAndPassword($host,$username,$password,["version" => 'Exchange2010_SP1', 'impersonation' => $email]);
$response = $api->getClient()->GetUserOofSettingsRequest(['Address' => 'someuser#mycompany.com']);
But get the following error.
Fatal error: Uncaught SoapFault exception: [Client] Function ("GetUserOofSettingsRequest") is not a valid method for this service in /Scripts/vendor/garethp/php-ews/src/API/NTLMSoapClient.php:119 Stack trace: #0 /Scripts/vendor/garethp/php-ews/src/API/NTLMSoapClient.php(119): SoapClient->__call() #1 /Scripts/vendor/garethp/php-ews/src/API/ExchangeWebServices/MiddlewareFactory.php(18): garethp\ews\API\NTLMSoapClient->__call() #2 /Scripts/vendor/garethp/php-ews/src/API/ExchangeWebServices.php(510): garethp\ews\API\ExchangeWebServices->garethp\ews\API\ExchangeWebServices\{closure}() #3 /Scripts/vendor/garethp/php-ews/src/API/ExchangeWebServices/MiddlewareFactory.php(32): garethp\ews\API\ExchangeWebServices->garethp\ews\API\{closure}() #4 /Scripts/vendor/garethp/php-ews/src/API/ExchangeWebServices.php(510): garethp\ews\API\ExchangeWebServices->garethp\ews\API\ExchangeWebServices\{closure}() #5 /Scripts/vendor/garethp/php-ews/src/API/ExchangeWebServices/MiddlewareFactory.php(48): garethp\ews\API\ExchangeWebServices->garethp\ew in /Scripts/vendor/garethp/php-ews/src/API/NTLMSoapClient.php on line 119
Thanks

Google AndroidPublisher Subscriptions acknowledge how to

I created a subscription for my Android app and here's my code to confirm subscription assignments, but I get an error
$packageName = "com.example.srkn";
$productId = "com.example.srkn.aylik";
$token = "<some token here>";
require 'vendor/autoload.php';
$client = new \Google_Client();
$client->setAuthConfig('ts.json');
$client->addScope('https://www.googleapis.com/auth/androidpublisher');
$service = new \Google_Service_AndroidPublisher($client);
$postBody = "okey";
$para = "test";
$purchase = $service->purchases_subscriptions->acknowledge($packageName, $productId, $token,$postBody,$para);
//echo json_encode($purchase);
Fatal error: Uncaught TypeError: Argument 4 passed to
Google_Service_AndroidPublisher_Resource_PurchasesSubscriptions::acknowledge()
must be an instance of
Google_Service_AndroidPublisher_SubscriptionPurchasesAcknowledgeRequest,
string given, called in /home/serkanka/public_html/dgr/onayla.php on
line 17 and defined in
/home/serkanka/public_html/dgr/vendor/google/apiclient-services/src/Google/Service/AndroidPublisher/Resource/PurchasesSubscriptions.php:40
Stack trace: #0 /home/serkanka/public_html/dgr/onayla.php(17):
Google_Service_AndroidPublisher_Resource_PurchasesSubscriptions->acknowledge('com.text.spec.s...',
'com.text.spec.s...','jlkehndmfjoaenc...', 'test', 'test') #1 {main}
thrown in
/home/serkanka/public_html/dgr/vendor/google/apiclient-services/src/Google/Service/AndroidPublisher/Resource/PurchasesSubscriptions.php
on line 40
The postbody (4th parameter) should be an instance of Google_Service_AndroidPublisher_SubscriptionPurchasesAcknowledgeRequest
You can set the developerPayload on the object like so:
$requestBody = new Google_Service_AndroidPublisher_SubscriptionPurchasesAcknowledgeRequest();
$requestBody->setDeveloperPayload('your_developer_payload');

call to a member function connection() on null laravel

Im testing out something in laravel but the code below gives me error and I couldnt figure out whats the problem
Code :
<?php
require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
$posts = \App\Models\Post::take(5)->get()->toArray();
file_put_contents('1.txt', print_r($posts, 1));
>
error :
Fatal error: Uncaught Error: Call to a member function connection() on null in /home/vowave/public_html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:3351 Stack trace: #0 /home/vowave/public_html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(3317): Illuminate\Database\Eloquent\Model::resolveConnection(NULL) #1 /home/vowave/public_html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1861): Illuminate\Database\Eloquent\Model->getConnection() #2 /home/vowave/public_html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1834): Illuminate\Database\Eloquent\Model->newBaseQueryBuilder() #3 /home/vowave/public_html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1804): Illuminate\Database\Eloquent\Model->newQueryWithoutScopes() #4 /home/vowave/public_html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(3561): Illuminate\Database\Eloquent\Model->newQuery() #5 /home/vowave/public_html/vendor/laravel/framework/sr in /home/vowave/public_html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php on line 3351
When you manually start laravel, you should call bootstrap method , like this:
<?php
$app = require __DIR__.'/bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
var_dump(Task::all());

Invalid JSON in influxdb-php

When a query is made, it retuns 404, invalid json error.
I use 8083 as port. Is there any another port for api.
Below is the code I use. Any help is welcome.
<?php
require '/vendor/autoload.php';
$client = new InfluxDB\Client('153.148.25.44', '8083');
$database = $client->selectDB('Meters');
$result = $database->getQueryBuilder()
->select('*')
->from('GDATA')
->limit(2)
->getResultSet()
->getPoints();
//$result = $database->query('select * from GDATAlimit LIMIT 5;');
//$points = $result->getPoints();
//$lastQuery = $client->getLastQuery();
echo '<pre>';
var_dump($result);
?>
Tested database connection, it is working.
Version is 0.13
Fatal error:
Uncaught exception 'InvalidArgumentException' with message 'Invalid JSON' in C:\xampp\htdocs\projectone\vendor\influxdb\influxdb-php\src\InfluxDB\ResultSet.php:30
Stack trace: #0 C:\xampp\htdocs\projectone\vendor\influxdb\influxdb-php\src\InfluxDB\Driver\Guzzle.php(100): InfluxDB\ResultSet->__construct('404 page not fo...')
#1 C:\xampp\htdocs\projectone\vendor\influxdb\influxdb-php\src\InfluxDB\Client.php(198): InfluxDB\Driver\Guzzle->query()
#2 C:\xampp\htdocs\projectone\vendor\influxdb\influxdb-php\src\InfluxDB\Database.php(78): InfluxDB\Client->query('Meters', 'SELECT * FROM "...', Array)
#3 C:\xampp\htdocs\projectone\vendor\influxdb\influxdb-php\src\InfluxDB\Query\Builder.php(261): InfluxDB\Database->query('SELECT * FROM "...')
#4 C:\xampp\htdocs\projectone\home.php(10): InfluxDB\Query\Builder->getResultSet()
#5 {main} thrown in C:\xampp\htdocs\projectone\vendor\influxdb\influxdb-php\src\InfluxDB\ResultSet.php on line 30
API port for InfuxDB v0.13 is 8086. I was using 8083, which is used for web.

Mink + Driver couldn't connect to host

I am trying to get Mink working on Centos/Apache, but it cannot connect. I have tried with Selenium2Driver, ZombieDriver and last Sahi but I always get a different error.
Right now with Sahi:
require __DIR__ . '/vendor/autoload.php';
$driver = new \Behat\Mink\Driver\SahiDriver('firefox');
$session = new \Behat\Mink\Session($driver);
$session->start();
$session->visit('http://google.it');
echo $session->getStatusCode();
and generate this error:
Fatal error: Uncaught exception 'Buzz\Exception\RequestException' with
message 'couldn't connect to host' in
/var/www/html/Test/vendor/kriswallsmith/buzz/lib/Buzz/Client/Curl.php:29
Stack trace: #0
/var/www/html/Test/vendor/kriswallsmith/buzz/lib/Buzz/Browser.php(130):
Buzz\Client\Curl->send(Object(Buzz\Message\Request),
Object(Buzz\Message\Response)) #1
/var/www/html/Test/vendor/kriswallsmith/buzz/lib/Buzz/Browser.php(82):
Buzz\Browser->send(Object(Buzz\Message\Request)) #2
/var/www/html/Test/vendor/kriswallsmith/buzz/lib/Buzz/Browser.php(36):
Buzz\Browser->call('http://localhos...', 'POST', Array, '') #3
/var/www/html/Test/vendor/behat/sahi-client/src/Connection.php(268):
Buzz\Browser->post('http://localhos...', Array, '') #4
/var/www/html/Test/vendor/behat/sahi-client/src/Connection.php(150):
Behat\SahiClient\Connection->post('http://localhos...') #5
/var/www/html/Test/vendor/behat/sahi-client/src/Client.php( in
/var/www/html/Test/vendor/kriswallsmith/buzz/lib/Buzz/Client/Curl.php
on line 29
I have installed with composer:
behat/behat
behat/mink
behat/mink-sahi-driver
behat/sahi-client
Why it cannot connect?

Categories