phpSPO and authentication - php

I need to access a file on SharePoint and I have installed phpSPO via Composer.
I use this code:
require_once('/vendor/autoload.php');
$username = 'myUsername';
$password = 'myPassword';
$fileUrl = "file-url";
$fileUrl = end(explode("https://xxxxxxxx.sharepoint.com", $fileUrl));
use Office365\PHP\Client\Runtime\Auth\AuthenticationContext;
use Office365\PHP\Client\SharePoint\ClientContext;
use Office365\PHP\Client\SharePoint\ListCreationInformation;
use Office365\PHP\Client\SharePoint\SPList;
$authCtx = new AuthenticationContext('https://xxxxxxxx.sharepoint.com');
But I get this error: Fatal error: Uncaught Error: Class "Office365\PHP\Client\Runtime\Auth\AuthenticationContext" not found ...
From composer.json:
{
"require": {
"vgrem/php-spo": "^2.5"
}
}
Any ideas?
Solution:
use Office365\Runtime\Auth\AuthenticationContext;
use Office365\SharePoint\ClientContext;
use Office365\SharePoint\ListCreationInformation;
use Office365\SharePoint\SPList;

Related

Class not found while using composer and docker

Im using this library https://serp-spider.github.io/documentation/search-engine/google/
When I follow their example I got this.
Fatal error: Uncaught Error: Class "Serps\SearchEngine\Google\GoogleClient" not found in /var/www/html/index.php:19 Stack trace: #0 {main} thrown in /var/www/html/index.php on line 19
This is my index.php
<?php
use Serps\SearchEngine\Google\GoogleClient;
use Serps\SearchEngine\Google\GoogleUrl;
$googleClient = new Serps\SearchEngine\Google\GoogleClient($httpClient);
$googleUrl = new GoogleUrl();
$google->setSearchTerm('simpsons');
$response = $googleClient->query($googleUrl);
$results = $response->getNaturalResults();
foreach($results as $result){
// Here we iterate over the result list
// Each result will have different data based on its type
}
?>
I've been thinking about what it could be for a while but I can't
I was missing the autoload, I added this line and works.
require 'vendor/autoload.php';
I changed the namespace and forgot to update it in composer.json
"autoload": {
"psr-4": {
"MyNamespace\\": "src"
}
},
Then run composer dump-autoload

Uncaught Error: Call to undefined method Kreait

I just created php web server and connected it to firebase. when I tried authentication, Sign up works just fine. but the problem is in Sign in. it keeps getting this error:
Fatal error: Uncaught Error: Call to undefined method Kreait\Firebase\Auth::signInWithEmailAndPassword() in /Applications/XAMPP/xamppfiles/htdocs/firebase_series/authActions.php:24 Stack trace: #0 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/firebase_series/authActions.php on line 24
here my authentication code:
<?php
include("includes/db.php");
if(isset($_POST['signup']))
{
$email = $_POST['emailSignup'];
$pass = $_POST['passSignup'];
$auth = $firebase->getAuth();
$user = $auth->createUserWithEmailAndPassword($email,$pass);
header("Location:index.php");
}
else
{
$email = $_POST['emailSignin'];
$pass = $_POST['passSignin'];
$auth = $firebase->getAuth();
$user = $auth->getUserWithEmailAndPassword($email,$pass);
if($user)
{
session_start();
$_SESSION['user'] = true;
header("Location:home.php");
}
}
?>
and here's my database connection code:
<?php
require __DIR__.'/vendor/autoload.php';
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;
use Kreait\Firebase\Auth;
// This assumes that you have placed the Firebase credentials in the same directory
// as this PHP file.
$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/google-service-account.json');
$apiKey = 'AIzaSyCHULFKW6Kl7FXZc3ZUTYL8fq0f90-kAJ0';
$firebase = (new Factory)
->withServiceAccount($serviceAccount, $apiKey)
// The following line is optional if the project id in your credentials file
// is identical to the subdomain of your Firebase project. If you need it,
// make sure to replace the URL with the URL of your project.
->withDatabaseUri('https://phpserver-f35e3.firebaseio.com/')
->create();
$database = $firebase->getDatabase();
?>
👋 I'm the maintainer of the SDK (kreait/firebase-php) you're using :)
Your error says
Call to undefined method Kreait\Firebase\Auth::signInWithEmailAndPassword()
but I don't actually see this method called in your code. A method called signInWithEmailAndPassword() doesn't exist as well, and you're using methods to initialize the SDK that have been deprecated for quite some time now - please make sure to be on the latest release of the SDK (4.40 at the time of this comment).
Once you have, you will have access to the Auth::verifyPassword($email, $password) method.
Your code could then look like this:
<?php
// includes/db.php
require __DIR__.'/vendor/autoload.php';
use Kreait\Firebase\Factory;
$factory = (new Factory())->withServiceAccount(__DIR__.'/google-service-account.json');
$auth = $factory->createAuth();
// no closing "?>"
<?php
include("includes/db.php");
// Have a look at https://www.php.net/filter_input to filter user input
if (isset($_POST['signup'])) {
$email = $_POST['emailSignup'];
$pass = $_POST['passSignup'];
$user = $auth->createUserWithEmailAndPassword($email,$pass);
header("Location:index.php");
exit;
}
$email = $_POST['emailSignin'];
$pass = $_POST['passSignin'];
if ($email && $pass && $user = $auth->verifyPassword($email, $pass)) {
session_start();
$_SESSION['firebase_user_id'] = $user->id;
header("Location:home.php");
exit;
}
echo "Authentication failed";
If you have further questions concerning the SDK, I'd like to invite you the Discord community dedicated to the SDK.

Call to undefined method Infusionsoft\Api\Rest\ContactService::addWithDupCheck()

This was working all this while with no issues and updates.
$user_id = $infusionsoft->contacts->addWithDupCheck($contact, 'Email');
Now all of a sudden it isn't
PHP Fatal error: Uncaught Error: Call to undefined method
Infusionsoft\Api\Rest\ContactService::addWithDupCheck() in
/home/user/public_html/infusionsoft/addContact.cli.php:29
~/public_html/infusionsoft$ cat composer.json
{
"require": {
"infusionsoft/php-sdk": "^1.0"
}
}
InfusionSoft has replaced their older XML-RPC API with REST. REST is now default. So I had to do :
$user_id = $infusionsoft->contacts('xml')->addWithDupCheck($contact, 'Email');

It will be displayed as Fatal error: Uncaught Error: Class 'eftec\bladeone' not found

I was trying to test BladeOne using PHP7.3.
composer.json
{
"name": "TEST",
"require": {
"eftec/bladeone": "^3.33"
},
"autoload": {
"psr-4": {
"eftec\\": "vendor/eftec/"
}
}
}
test.php
require "vendor/autoload.php";
Use eftec\bladeone;
$views = __DIR__ . '/views';
$cache = __DIR__ . '/cache';
$blade = new BladeOne($views,$cache,BladeOne::MODE_AUTO);
// $blade -> setAuth( ' johndoe ' , ' admin ' );
echo $blade->run("hello",array("variable1"=>"value1"));
This error appears when you run it.
Fatal error: Uncaught Error: Class 'eftec\bladeone' not found in /*/test.php on line 8
Error: Class 'eftec\bladeone' not found in /*/test.php on line 8
I also found a link like this but it didn't work.
Why does this error occur?
Replace Use eftec\bladeone; to use eftec\bladeone\BladeOne;.
And remove:
"autoload": {
"psr-4": {
"eftec\\": "vendor/eftec/"
}
}
From your composer.json.
Hope help you.
You included only the namespace, not the class name
Change your Use statement by this one :
use eftec\bladeone\BladeOne;
Or instantiate the class like this :
$blade = new bladeone\BladeOne($views,$cache,BladeOne::MODE_AUTO);
(Don't do both)

Fatal error: Uncaught Error: Class 'Foolz\SphinxQL\Connection' not found

I installed Foolz SphinxQL Query Builder for PHP with composer using the following json file:
{
"require": {
"foolz/sphinxql-query-builder": "^2.0"
}
}
My php is as follows:
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Foolz\SphinxQL\SphinxQL;
use Foolz\SphinxQL\Connection;
error_reporting(E_ALL);
ini_set('display_errors', 1);
// create a SphinxQL Connection object to use with SphinxQL
$conn = new Connection();
$conn->setConnectionParams('127.0.0.1', 9306);
$query = SphinxQL::create($conn)->select('*')
->from('test1')
->match('#test document');
# ->where('banned', '=', 1);
$result = $query->execute();
var_dump($result);
?>
Using my debugger I see the autoloader (function findFileWithExtension) is trying to find the file at /mnt/i/var/www/vhosts/my.play.net/sphinx/vendor/composer/../foolz/sphinxql-query-builder/Connection.php when it should presumably be looking in /mnt/i/var/www/vhosts/my.play.net/sphinx/vendor/composer/../foolz/sphinxql-query-builder/Drivers/Mysqli/Connection.php where it is actually located.
Can anyone advise why I might be seeing this and how I fix it?
You're using incorrect namespace. To get vendor/foolz/sphinxql-query-builder/src/Drivers/Mysqli/Connection.php you need to use Foolz\SphinxQL\Drivers\Mysqli\Connection as FQN:
use Foolz\SphinxQL\SphinxQL;
use Foolz\SphinxQL\Drivers\Mysqli\Connection;

Categories