I've recently taken on the task of making a quick and dirty static html page that will use php to access Twilio and reply with an SMS. I am new to Twilio, and was following this tutorial:
http://www.twilio.com/docs/quickstart/php/sms/sending-via-rest
When that failed I went back to check if I had skipped any steps after downloading the php zip and read over the content in the install page of the Twilio website, but even that didn't make sense, since I have never herd of PEAR and simply downloaded the php zip file and started working.
Now I am not sure if I even installed Twilio correctly(as stated above I just downloaded the zip folder), but I do know I changed the root directory for Wamp as advised by this site:
http://www.ruifeio.com/2011/01/30/change-the-www-root-directory-on-wampserver/
since all the tutorials said it was ok to use WAMP and because I had it already in my machine:
However, even after making that change, correctly I hope, I can't seem to get Twilio to send me a text.
My code is basically a copy and paste job from the tutorial I've listed above, it looks as follows:
<?php
require "C:\Users\Kevin\Marco Polo\\twilio-php-master\Services\Twilio.php";
$AccountSid = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$AuthToken = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy";
$client = new Services_Twilio($AccountSid, $AuthToken);
$people = array(
"+13466033189" => "Kevin",
"+16462805711" => "Loca",
"+17188390403" => "Stefa",
"+17183405728" => "Sweet Chocolate Man"
);
foreach($people as $number => $name){
$sms = $client->account->sms_messages->create(
"732-704-799",
$number,
"Hey $name, YOLO!!!! -Nick R. :P
P.S. do not reply"
);
echo "Sent message to $name";
}
?>
EDIT
After making the changes suggest by #Brainless Box and #CaseySoftware I was about to get rid of one error and only have three
The three errors are, in chronological order, as follows:
Warning: file_get_contents(): ailed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in C:\Users\Kevin\Marco Polo\twilio-php-master\Services\Twilio\HttpStream.php on line 61
Fatal error: Uncaught exception 'Services_Twilio_HttpStreamException' with message 'Unable to connect to service' in C:\Users\Kevin\Marco Polo\twilio-php-master\Services\Twilio\HttpStream.php on line 64
Services_Twilio_HttpStreamException: Unable to connect to service in C:\Users\Kevin\Marco Polo\twilio-php-master\Services\Twilio\HttpStream.php on line 64
I am all very new to this and hardly understand what is going on and where I went wrong and whether the mistake is in my code or in my installation of Twilio. If someone can lend me a hand that would be great.
Thanks Everyone :)
You don't have the SSL extension enabled in your Wamp configuration; to enable the extension, go to your WAMP directory (something like C:\path\to\wamp\bin\php\php#.#.#\php.ini) and uncomment ;extension=php_openssl.dll.
Be sure to restart WAMP after.
Related
I'm very new to Braintree and would appreciate probably a simple answer to something I've been stuck on for a while. I'm running Braintree with PHP on the server-side and I've got it working perfectly locally. However, when I move the same files to my web hosting server it doesn't seem to get the same result.
index.php
require_once 'vendors/braintree/Braintree.php';
$gateway = new Braintree_Gateway([
'environment' => 'sandbox',
'merchantId' => 'xxx',
'publicKey' => 'xxx',
'privateKey' => 'xxx'
]);
I get the following error:
PHP Fatal error: Uncaught Error: Class 'Braintree_Gateway' not found in ...
I'm guessing I need to do more than just simply use FTP to transfer the Braintree files to the server to install it. If so, how would I do that? Or if a web hosting server isn't the correct place to be hosting the Braintree Server what should I be looking?
So after countless hours I've finally found the silly mistake that was being made.
Change the following code inside autoload.php:
$fileName = dirname(__DIR__) . '/lib/';
To the directory that you have uploaded your Braintree files too.
Hopefully this helps someone in the future :)
I just installed CouchBase and the .dll files for XAMPP. I am following their example on how to connect: "Hello Couchbase" https://developer.couchbase.com/documentation/server/current/sdk/php/start-using-sdk.html
This code:
$bucketName = "default";
// Connect to Couchbase Server
$cluster = new CouchbaseCluster("couchbase://127.0.0.1");
$bucket = $cluster->openBucket($bucketName);
gives me:
LCB_AUTH_ERROR: Authentication failed. You may have provided an invalid username/password combination
I have a fresh installation, and following their guide #1, what am I doing wrong? I don't remember setting a password, I went to the CouchBase admin page and I can't find a way to change any password.
I sympathize here -- I'm having the same error (and no, it's not you, the docs have been neglected). Instantiating the CouchbaseCluster doesn't throw the error, it's actually the openBucket() method that causes problems, and for me, the problem was that the bucket didn't exist (it would be nice if the Couchbase error were in the right ballpark instead of bumbling around in irrelevant confusion). Here's some code that worked for me:
$cluster = new CouchbaseCluster('http://127.0.0.1:8091');
$manager = $cluster->manager('MYUSER', 'MYPASSWORD');
$manager->createBucket('new_bucket');
This does throw some errors:
[cb,WARN] (htconfig L:130 I:0) <couchbase:8091> (CTX=0x5601e6fd7e90,bc_http) Got 404 on config stream. Assuming terse URI not supported on cluster
[cb,EROR] (htconfig L:122 I:0) <couchbase:8091> (CTX=0x5601e6fd7e90,bc_http) Got 404 on config stream. Assuming bucket does not exist as we've tried both URL types
[cb,EROR] (htconfig L:142 I:0) <couchbase:8091> (CTX=0x5601e6fd7e90,bc_http) Got non-success HTTP status code 404
But it does work. The Couchbase forums are a better place for these types of questions -- they respond pretty quickly over there.
Thought I would drop a question, as this is giving me a proper headache
I have a PHP application which uploads files into SoftLayer Object Storage containers.
To communicate with the Object Storage API I am using the PHP bindings from
https://github.com/softlayer/softlayer-object-storage-php
and referenced them from my composer.json file
"softlayer/objectstorage": "dev-master",
Retrieving object container files and urls is working all fine.
But I keep having problems with uploading files though, specially depending on their size. It used to work couple of days ago but some reason stopped working recently
Here is the 'out-of-the-box' code I am using for uploading files:
$options = array('adapter' => ObjectStorage_Http_Client::SOCKET, 'timeout' => 10);
$objStorage = new ObjectStorage('', '', '', $options);
try {
$newFile = $objStorage->with('RemoteFilePath')
->setLocalFile($PathTolocalFile)
->create();
return $newFile->getUrl();
}
catch (Exception $e) {
return $e->getMessage();
}
For some reason, uploading a file that is under 1Mb works. But any file with a size bigger than this, the ->create() request eventually times out, no exception is thrown and I keep getting these error in my log:
xxx.xxx.xxx.xx - [05/06/16 03:47:02] Warning: fwrite(): SSL operation failed with code 1. OpenSSL Error messages:
error:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry (/var/www/vendor/softlayer/objectstorage/lib/ObjectStorage/Http/Adapter/Socket.php:132)
As those bindings are essentially a wrapper round curl, I then tested with CURL myself see if I could upload a file bigger than 1M to Softlayer Storage Container. It turns out it succeeded using CURL both on my dev machine and staging server!
curl -i -XPUT -H "X-Auth-Token: {{MyAuthToken}}" --data-binary "#BigFile.txt" https://lon02.objectstorage.softlayer.net/v1/{{MyAuthTokenKey}}/{{MyContainer}}/BigFile.txt
Have you ever come across this? I don't understand why it suddenly stopped working.
Has anyone any idea?
Thanks for reading
I was not able to reproduce your issue, I was able to upload files higher than 2 MB using your code.
Anyway, the issue that you have is related to SSL/OpenSSL broken, take a look the following links in order to get more information about it and how to solve it:
Bug #54439 SSL/OpenSSL
broken
fwrite(): SSL operation failed with code 1. OpenSSL Error
messages:\nerror:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write
retry IN
PHP
Why am I getting “error:1409F07F:SSL routines:SSL3_WRITE_PENDING:
bad write retry” error while attempting an
SSL_write?
I am trying to connect to the google API from a localhost, but keep on receiving an exception (key changed - in text below).
Warning: file_get_contents(compress.zlib://https://www.googleapis.com/books/v1/volumes?q=Henry+David+Thoreau&filter=free-ebooks&key=bItatTTTTT7amAHYSaROTTTTTbtttuuuuuuuu) [function.file-get-contents]: failed to open stream: operation failed in C:\zendProject\zf2\vendor\google\apiclient\src\Google\IO\Stream.php on line 115
The code I am using in my browser comes straight from the API Guide and reads:
$client = new \Google_Client();
$client->setApplicationName("rent");
$service = new \Google_Service_Books($client);
$optParams = array('filter' => 'free-ebooks');
$results = $service->volumes->listVolumes('Henry David Thoreau', $optParams);
I think my problems relate to the config file, and that fact I am working off the localhost development server.
'Google_Auth_OAuth2' => array(
'application_name' => 'www.example.com',
'client_id' => '4498xxxxx061-3333xxxx9pjcpkbqhoxxxxxxxxxxx.apps.googleusercontent.com',
'client_secret' => '8xxxxxxxxx333xxxxxxxxx',
'redirect_uri' => 'http://localhost',
'developer_key' => 'AxxxxxxzBjpxxxxxaxxxxxxZxxx1xxxxx',
In the new developer console I have created a new client ID for the project and inserted the "Client_id", "Client_secret", etc.
I have also enabled the relevant APIs for Calenders and Books.
I have tested my API key on the URL I found for google fonts - so I am sure I have the right developer key.
I suspect the issue may be around the local host in uri fields, what do I need to put in here?
Does anyone know what I am doing wrong.
UPDATE: I found a post that suggested getting the HTTP response code here:
The response from the server is 304 - not sure if this helps
UPDATE: #Carlos Roubles - was correct I was using the incorrect version. Just in case anyone else runs into this issue - the composer information on the google website appears to be incorrect.
I previously used "google/apiclient": "1.0." this appears in the google documentation. I have now tried "google/apiclient": "1." and this seems to have fixed the problem.
Thats a problem with file_get_contents rather that with the api.
Most people changes file_get_contents to CURL for accesing remote files.
Anyways, i was checking the library and i cannot find any call to file_get_contents in all the stream.php file
https://github.com/google/google-api-php-client/blob/master/src/Google/IO/Stream.php
and in line 115, what we have is a commented line, so what comes to my mind is that yu are not using the last version of the library. Also, i see that in this version they make the request with fopen.
So you can try to update it, and probably this fixes the issue
I am looking for help with this problem and I hope someone give me that help. The error is the following:
Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://example.com/index.php/api/?wsdl' : failed to load external entity "http://example.com/index.php/api/?wsdl" in
/var/www/presentacion/app/code/local/Pengo/Extension/Model/Something.php on line 28
And the code that I'm using to connect to it is something like this:
$this->_soap = new SoapClient(http://example.com/index.php/api/?wsdl);
and there is where it says is the error.
I have been serching in Google, PHP forums, here in StackOverflow and Magento itself but I don't find the solution anywhere.
What I had seen is that the WSDL is never get parsed or loaded as the error says and none of its functions.
I tried connecting like this:
$options['location'] = http://example.com/index.php/api/?wsdl;
$options['uri'] = 'urn:Magento';
$this->_soap = new SoapClient(null, $options);
like this it doesn't dispatch any error like the others but there aren't functions to use, like in the other case it doesnt' load and parse the WSDL.
I am a bit frustrated because I have been developing this like 1 month and now that I am making some tests it shows this message, I had test it when it was really empty and new and it worked fine.
So any help would be appreciated.
Thank you.
Nine times out of ten this error is Magento is telling you it can't load the WSDL file. Magento is telling you this. It's not your local client code that's complaining.
Magento uses the PHP SoapServer object to create its SOAP API. The SoapServer object needs to access the WSDL as well. Try running the following from your server's command line
curl http://example.com/index.php/api/?wsdl
If I'm right, the above will timeout/fail.
Because of some quirks in DNS, it's surprisingly common that a server won't be able to access itself via its domain name. If this is the case, the quickest fix is adding an entry to the server's hosts file. (Talk to your server admin if none of that made sense)
Well after all the things that I test the only one that worked for me, I don't know why but it worked, was doing this in two separate machines. I tried that because I read that somewhere and I just do it and my Magento and Webservice now works perfectly. Whenever I try to do this local it dispatch the same error.
I hope this can help someone in the future and they don't have to knock their head on the wall because of this problem.
Thank you all for your answers and comments.
Alan Storm is right on the Money here!
Make sure that you check your server Hosts File, and that it includes an entry for both domain and www.domain. Espicialy important if you are doing server rewrites.