Posting message using Facebook SDK for PHP - php

Hello I'm working with a PHP code using Facebook SDK to post a message on a facbook page which I am the admin it's ok when I work in localhost but when I hosted my page on a web server it gives me the following error:
Fatal error: Class 'Facebook\FacebookSession' not found in /var/www/simo/index.php on line 48
The lines of code that cause problem:
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookSession;
use Facebook\FacebookRequest;
require "vendor/autoload.php";
session_start();
$appId='358738637667835';
$appSecret='92841aa4b36c9c37a4d779e801db3d6f';
FacebookSession::setDefaultApplication($appId,$appSecret);//(line 48)
The thing that should be noted is that the version of my server’s PHP is “PHP 5.4.39” that normally understands the instruction "use".
Thank you for giving me a solution or a suggestion.

This problem happens as a result of incorrect paths. If you downloaded the PHP SDK , make sure it contains a file called "autoload.php", then add the following line
require __DIR__ . '/facebook-php-sdk/autoload.php';
before the "use statement"
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookSession;
the autoload.php will fix all paths and do the mapping for you

Related

Loading class in regualr php file in Laravel project

I have a laravel project and in it, I create a regular (.php) file that I am posting some data to. In that file, I want to use a class that I installed using composer in the Laravel project. When I post data to the page I am getting the error No such file in directory and require(): Failed opening required 'vendor/autoload.php. How can I resolve this my project is almost complete if I can get this working.
I've tried: require "class name" but the same error.
PHP file posting to:
<?php
require "vendor/autoload.php";
require 'vendor\lcobucci\jwt\src\Builder.php';
require 'vendor\lcobucci\jwt\src\Signer.php';
//I've tried using these require statements
use \vendor\Lcobucci\JWT\Builder;
use \vendor\Lcobucci\JWT\Signer\Hmac\Sha256;
someFunctiion(){
// do stuff with function from class
}
?>
I expect that when I post to this page, the function from the class I am 'using' will be called but instead, it's saying require() failed to open class.

Error integrating Authorize.net payment gateway: MerchantAuthenticationType not found

I am integrating Authorize.net payment gateway in my project in php. But here I am facing this error.
Fatal error: Class 'net\authorize\api\contract\v1\MerchantAuthenticationType' not found in /opt/lampp/htdocs/payment/charge-credit-card.php on line 9
require 'vendor/autoload.php';
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
define("AUTHORIZENET_LOG_FILE","phplog");
// Common setup for API credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType()
I have downloaded PHP-SDK from github and did as they say.
Try replacing: require 'vendor/autoload.php';
With: require 'autoload.php';
I am an amateur and I had used composer and it was doing weird things. I had to find and move a bunch of files to get the whole thing working. The hardest part was finding the right autoload.php.
I hope it helps...newbie here so...

Mailgun SDK unable to find required classes (php)

I'm trying to use the Mailgun API SDK to send emails from my test server. I downloaded the SDK itself as I am not currently using Composer.
However, when I try to instantiate a Mailgun object, I get this error:
Fatal error: Class 'Mailgun\Connection\RestClient' not found in /var/www/mysite.xyz/www/inc/libs/Mailgun/Mailgun.php on line 38
Which I fixed by adding require "Connection/RestClient.php"; to the Mailgun.php file. However, this in turn caused its own error.
Fatal error: Class 'GuzzleHttp\Client' not found in /var/www/mysite.xyz/www/inc/libs/Mailgun/Connection/RestClient.php on line 41
This is included in my includes.php, so for all pages.
#Mailgun php functions
require_once "libs/Mailgun/Mailgun.php";
use Mailgun\Mailgun;
Then, when I try to use this;
# First, instantiate the SDK with your API credentials and define your domain.
$mg = new Mailgun\Mailgun("key-myactualkey");
$domain = "myactualdomain.xyz";
print "Email to send is ".$welcomeemail; #Never gets reached
It causes those fatal errors and the program grinds to a halt.
Why is this happening and how do I fix it?
I had the same problem and fixed it by using composer which is easier then you might think. Just follow these instructions (locally, on your computer, where PHP should be installed):
https://github.com/mailgun/mailgun-php/blob/master/SharedHostInstall.md
Then upload all files generated to your server in a separate directory.
Then include the following lines to your script:
require 'your/path/to/these/files/vendor/autoload.php';
use Mailgun\Mailgun;
Create a new Mailgun object like this:
$mg = new Mailgun("your-secret-key");

Require paths not working using google api php library

My problem is the next one,
I tried to integrate the google login using OAuth 2.0 feature into my company backend.
I tested it on my domain , www.gabrielestevez.com, everything here works perfect, there is no problem with the require paths, everything runs smothly
But , the company backend directories has the following structure
I'm using a mvc framework developed by me , the Google_SL.php file contains the class where I make the first two require_once
require_once 'Google/Client.php';
require_once 'Google/Service/Oauth2.php';
which works fine, but then when it goes to the client.php and is trying to load this class
require_once 'Google/Auth/AssertionCredentials.php';
is not working , this is the error
An error occurred in script '/home/xxx/public_html/admin/hmf/Core/library/auth/Google/Client.php' on line 18: require_once(Google/Auth/AssertionCredentials.php) [function.require-once]: failed to open stream: No such file or directory
Date/Time: 9-19-2014 11:50:29
, I don't want to change manually all the path within this library because I know there is got to be a better solution to this
any input is appreciated.
for future reference
I fixed my issue using this
set_include_path($_SERVER['DOCUMENT_ROOT'] . '/admin/hmf/Core/library/auth/' . PATH_SEPARATOR . get_include_path());
Try use __DIR__ to get the current directory of the script. Not exactly sure where your AssertionCredentials.php is, but try something like
require_once(__DIR__ . '/Google/Auth/AssertionCredentials.php');

How to setup a php client Thrift 0.9.1 ...

I'm trying to setup a php client for RPC with a HBase Thrift server but I'm getting some errors at the begining ... I've compilated the HBase.thrift file (with the 0.9.1 compiler) and I've put the 2 generated files like bellow (/ is the root of my project, I'm using apache server on ArchOS) :
/include/Hbase.php
/include/Types.php
I've included the lib folder of thrift0.9.1/lib/php/lib (composed of Thrift and sub folders) under / and so I've the following file system :
/include/HBase.php
/Types.php
/Thrift/Base
/ClassLoader
/Exception
/ext
...
To be able to use my service (HBase.php) I've to load files so my code is the following :
<?php
$GLOBALS['THRIFT_ROOT'] = PHYSICAL_PATH;
// Load up all the thrift stuff
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Transport/TTransport.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Transport/TSocket.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Protocol/TProtocol.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Protocol/TBinaryProtocol.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Transport/TBufferedTransport.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Type/TMessageType.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Factory/TStringFuncFactory.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/StringFunc/TStringFunc.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/StringFunc/Core.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Type/TType.php';
use Thrift\Protocol\TBinaryProtocol;
use Thrift\Transport\TSocket;
use Thrift\Transport\TSocketPool;
use Thrift\Transport\TFramedTransport;
use Thrift\Transport\TBufferedTransport;
//hbase thrift
require_once ('Hbase.php');
require_once ('Types.php');
?>
When I'm charging the different files, I'm getting an error for this line --require_once ('Types.php');-- and the error is : Fatal error: Class 'Thrift\Exception\TException' not found in /var/www/html/POCThrift2/include/Types.php on line 1266
I understand it like : When I tried to include Types.php, the Thrift\Exception\TException namespace was not use (despite the use Thrift\Exception\TException; in the beginig of the Types file) but I don't know why I'm getting his error ... can you help me ? Does anyone has encountered this problem before ? Thx in advance, I'm stuuuck right now ...

Categories