I am working with Php and "Discord". Right now, I am getting the following error:
Fatal error: Uncaught Error: Class 'Discord\Client' not found",But in my "src folder
Client library exists, I have "Vendor" and "src" folders, and client.php is there. Here is my code - where I am going wrong?
<?php
include __DIR__.'/vendor/autoload.php';
include 'vendor/autoload.php';
use Discord\Discord;
use Discord\Parts\Interactions\Command\Command; // Please note to use this correct namespace!
use Discord\Client;
use Discord\Parts\Interaction;
use Discord\Parts\Choices;
$client = new Client([
'public_key' => 'b81678ce3e98ff78f9387c3cxxxxxxxxxxxxxxxx',
'uri' => '0.0.0.0:80', // if you want the client to listen on a different URI
'logger' => $logger, // different logger, default will write to stdout
'loop' => $loop, // reactphp event loop, default creates a new loop
'socket_options' => [], // options to pass to the react/socket instance, default empty array
]);
You need to use
$client = new Discord([
'token' => 'b81678ce3e98ff78f9387c3cxxxxxxxxxxxxxxxx'
]);
Instead of client because library team-reflex/discord-php using Discord class instead of Client in direct interaction.
Here you can find the use cases.
Related
I have created php file. It contains details about to access (wsdl)xml file and function. I need to call a function with paramaters but i can't able to call a function. So, I have been given a WSDL file and I need to create a SOAP service for it in PHP. Could any one tell me what the correct way of doing it is?
Here is link of the WSDL: http://178.211.55.56/se/ws/wf_ws.php?wsdl
and
Here is my php code:
require_once 'lib/nusoap.php';
ini_set("soap.wsdl_cache_enabled", "0");
$soapclient = new nusoap_client("http://178.211.55.56/se/ws/wf_ws.php?wsdl",'wsdl');
$soapclient->setHTTPProxy("soap:address_location",8080,"usr_name","pwd");
when run above the php code return this error:
wsdl error: Getting "WSDL link" - HTTP ERROR: Couldn't open socket
connection to server "WSDL link" prior to connect(). This is often a
problem looking up the host name.
Try to use http://php.net/manual/en/class.soapclient.php
All you need is:
Create SOAP client:
$client = new SoapClient("http://178.211.55.56/se/ws/wf_ws.php?wsdl");
You can pass many options to the constructor, such as proxy, cache settings, etc.
Some examples for you:
$client = new SoapClient("some.wsdl", array('soap_version' => SOAP_1_2));
$client = new SoapClient("some.wsdl", ['login' => "some_name", 'password'=> "some_password"]);
$client = new SoapClient("some.wsdl", ['proxy_host' => "localhost", 'proxy_port' => 8080]);
If ssl certificate is wrong you can ignore it. Example is here: https://gist.github.com/akalongman/56484900eaf19b18cfbd
Call one of the service defined functions:
$result = $client->getResult(['param_name' => 'param_value']);
Pay attention that your service function may have required parameters. Usually it can be found in the result message.
I'm trying to use Standalone Twig to send emails with Swiftmailer. I'm following for the instructions at the "With a pure Swiftmailer/Twig" section.
This is my code:
require_once('/var/www/folder/includes/vendor/autoload.php');
$loader = new Twig_Loader_Filesystem(array('/var/www/templates/utilities/test'));
$twig = new Twig_Environment($loader, array(
'cache' => '/var/www/templates/cached',
'auto_reload' => true, // set to false to improve performance (Note: You have to clear the cache manually whenever a template is changed)
'debug' => true,
'use_strict_variables' => false,
));
$twig->addExtension(new Twig_Extension_Debug());
$swiftMailerTemplateHelper = new \WMC\SwiftmailerTwigBundle\TwigSwiftHelper($twig, '/var/www/templates/utilities/test');
// I'm not exactly sure what the value for the second parameter is supposed to be.
//The instructions referenced just list a variable called $web_directory.
//I'm assuming they just mean a path to where the templates are stored.
echo "hello world";
This is the error I'm getting:
PHP Fatal error: Class
'WMC\SwiftmailerTwigBundle\TwigSwiftHelper' not found in
/var/www/apps_mymea/utilities/test/email.php on line 16
The namespace in the referenced documentation is incorrect.
The correct syntax is:
$swiftMailerTemplateHelper = new \WMC\SwiftmailerTwigBundle\Mailer\TwigSwiftHelper($twig, '/var/www/templates/utilities/test');
//It was missing the \Mailer\ in the class path.
I suspect the finer mechanics of this question are wider than just the specific class library I'm looking to use, in this instance it's the use case I'm struggling with.
I'm looking at implementing the DMS Meetup API for PHP ( https://github.com/rdohms/meetup-api-client ) yet having installed the codebase and project dependencies I'm getting the error
Fatal error: Class 'MeetupOAuthClient' not found in...
The basic structure I have is
require('vendor/autoload.php');
// OAuth Authentication
$config = array(
'consumer_key' => '*****',
'consumer_secret' => '*****',
'token' => '*****',
'token_secret' => '*****',
);
$client = MeetupOAuthClient::factory($config);
It's suggesting the library isn't being loaded - but my understanding is the autoload.php should handle this no?
The DMS library uses namespaces, and you need to tell the autoloader where to find it in those namespaces.
After your require line, add the following and things should work:
use DMS\Service\Meetup\MeetupOAuthClient;
You could also change the last line to the following and get a similar effect:
$client = DMS\Service\Meetup\MeetupOAuthClient::factory($config);
Im using the Zip method with aws-sdk-php and I get an error with my php app when calling ec2client factory object (or the preceding Use clauses, Im not sure...)
require LIBS_PATH . 'aws-sdk-php/aws-autoloader.php';
use Aws\Common\Aws;
use Aws\Common\Enum\Region;
use Aws\Ec2\Ec2Client;
public function createAWSApp($app_id)
{
// Get users region
$this->app->aws_region = $this->getUserAWSRegion();
// Setup the EC2 object
$this->ec2client = Ec2Client::factory(array(
//'profile' => '<profile in your aws credentials file>',
'key' => AWS_ACCESS_KEY_ID,
'secret' => AWS_SECRET_ACCESS_KEY,
'region' => $this->app->aws_region
));
...
The app's framework results in error
The file Aws\Ec2\Ec2Client.php is missing in the libs folder.
If I remove the Use clauses and explicitly name the files such as with a require_once :
require LIBS_PATH . 'aws-sdk-php/aws-autoloader.php';
use Aws\Common\Aws;
use Aws\Common\Enum\Region;
//use Aws\Ec2\Ec2Client;
require_once LIBS_PATH . 'aws-sdk-php/Aws/Ec2/Ec2client.php';
public function cr...
I get a similar message but looks like PHP default cannot find file error:
Warning: require_once(libs/aws-sdk-php/Aws/Ec2/Ec2client.php): failed to open stream: No such file or directory
LIBS_PATH is correct and works for other libraries Im using, the aws-sdk-php files are definitely present etc.
Please help...
I am working on installing the aws sdk for PHP on my Windows machine (Win7 64 bit) PHP v 5.5.12.
I tried using all the 3 methods viz Composer,zip and PHAR mentioned here.All the 3 ways give me the same error as below.
Warning: SimpleXMLElement::__construct(): Entity: line 1: parser error : Space required after the Public Identifier in C:\wamp\www\aws-sdk-php-master\src\Aws\Common\Exception\Parser\DefaultXmlExceptionParser.php on line 41
Here's the function which givess the error
public function parse(RequestInterface $request, Response $response)
{
$data = array(
'code' => null,
'message' => null,
'type' => $response->isClientError() ? 'client' : 'server',
'request_id' => null,
'parsed' => null
);
if ($body = $response->getBody(true)) {
$this->parseBody(new \SimpleXMLElement($body), $data); //THIS LINE GIVES ERROR
} else {
$this->parseHeaders($request, $response, $data);
}
return $data;
}
Here is how I try to use it.
error_reporting(E_ALL);
define('AWS_KEY', 'MyAWSKEY');
define('AWS_SECRET_KEY', 'MYSECRETKEY');
define('HOST', 'http://localhost'); //tried changing host to diff values,but don't
//think thats the issue
// require the AWS SDK for PHP library
require 'aws-autoloader.php';
//require '../../aws.phar';
use Aws\S3\S3Client;
// Establish connection with an S3 client.
$client = S3Client::factory(array(
'base_url' => HOST,
'key' => AWS_KEY,
'secret' => AWS_SECRET_KEY
));
$o_iter = $client->getIterator('ListObjects', array(
'Bucket' => 'mybucketname'
));
foreach ($o_iter as $o) {
echo "{$o['Key']}\t{$o['Size']}\t{$o['LastModified']}\n";
}
Heres the stacktrace
[17-Jul-2014 04:19:01 Europe/Paris] PHP Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\wamp\www\aws-sdk-php-master\src\Aws\Common\Exception\Parser\DefaultXmlExceptionParser.php:41
Stack trace:
#0 C:\wamp\www\aws-sdk-php- master\src\Aws\Common\Exception\Parser\DefaultXmlExceptionParser.php(41): SimpleXMLElement- >__construct('<!DOCTYPE HTML ...')
#1 C:\wamp\www\aws-sdk-php-master\src\Aws\S3\Exception\Parser\S3ExceptionParser.php(33): Aws\Common\Exception\Parser\DefaultXmlExceptionParser->parse(Object(Guzzle\Http\Message\Request), Object(Guzzle\Http\Message\Response))
#2 C:\wamp\www\aws-sdk-php-master\src\Aws\Common\Client\ExpiredCredentialsChecker.php(61): Aws\S3\Exception\Parser\S3ExceptionParser->parse(Object(Guzzle\Http\Message\Request), Object(Guzzle\Http\Message\Response))
#3 C:\wamp\www\aws-sdk-php-master\vendor\guzzle\guzzle\src\Guzzle\Plugin\Backoff\AbstractBackoffStrategy.php(39): Aws\Common\Client\ExpiredCredentialsChecker->getDelay(0, Object(Guzzle\Http\Message\Request), Object(Guzzle\Http\Message\Resp in C:\wamp\www\aws-sdk-php-master\src\Aws\Common\Exception\Parser\DefaultXmlExceptionParser.php on line 41
Tried googling it and learnt might be due to magic_quotes in php.ini to be on,but thats not the case,actually I don't have magic_quotes itself in my ini file.
Checked the stack trace and it shows the same error.I am not able to figure out if its a system issue or some configuration problem as I get it for all the methods.
Is this a issue with some configuration? OR I am missing something?
Oh, I see what's going on. You should not be setting the base_url parameter. By setting that value you are telling the SDK to send the requests to your localhost, instead of the actual S3 service. Your localhost is returning HTML, not a XML, which is why SimpleXML is throwing parse errors.
To use S3, you should provide your credentials (key and secret), and optionally a region if you are intentionally not using S3's default region. Do not override the base_url value, which is something that the SDK resolves internally based on its knowledge of the service endpoints.
Note: we also encourage users to use a credential profile profile instead of explicit credentials (key and secret) so you can store your credentials in a file outside of your code and project, in order to prevent accidental credential leaks (e.g., committing credentials into version control). The S3 page in the User Guide walks you through how to properly create the client and provides a link to learn more about the credential file/profile.