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
Related
I'm trying to get solution for this issue but can't find it out.
I'm developing a WordPress plugin using Woocommerce APIs, i.e trying to insert a product reading from external JSON source. So when I try to call
$woocommerce->get( 'products', $data );
I get a fatal error like that:
Fatal error: Uncaught Automattic\WooCommerce\HttpClient\HttpClientException: Error: Firma non valida - la firma fornita non corrisponde. [woocommerce_rest_authentication_error] in /Users/hal/Documents/www/wordpress/wp-content/plugins/.../vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php:324
(StackTrace not reported here, not useful to find other informations).
Error reported is 401, about this most weird thing is that the same code on localhost does not work, if I upload & try same code it on production VPS ... it works. Searched on many topics about this, no clear responses until now so sorry for duplicate, if is this the case.
$woocommerce was previously instanced as:
$woocommerce = new Client(
'http://localhost/wordpress',
'ck_...', // Your consumer key
'cs_...', // Your consumer secret
[
'wp_api' => true, // Enable the WP REST API integration
'version' => 'wc/v2' // WooCommerce WP REST API version
]
);
ck/cs pairs was just generated from wordpress, site url is obviously http://localhost/wordpress (and I tried without success i.e http://localhost/wordpress/, https://localhost/wordpress and so on)
If this could matter (...and I guess yes), I'm trying to debug this code on MAMP (apache on 80 port, mysql on 3306) running # localhost w/ basic installation, on MacOS Sierra 10.12.6.
Hope I was clear and anyone solved this problem, thanks in advance
If You are using http request then you have to user oauth for authorization for rest api
I am working on a project that is hosted on Google App Engine, and using app_devserver for local development. At the start I had problems with certificates but when I finally got over that error I am getting this new error
I am using Windows 10 and PHPstorm for development.
Error:
Message: cURL error 0: The cURL request was retried 3 times and did
not succeed. The most likely reason for the failure is that cURL was
unable to rewind the body of the request and subsequent retries
resulted in the same error. Turn on the debug option to see what went
wrong. See https://bugs.php.net/bug.php?id=47204 for more information.
(see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
Looks like this error is saying that the request is made and successfull but the body could not be resolved or parsed? How can I resolve it?
This is my PHP code if needed: (simple call to tag manager api v2)
$client = new Google_Client();
$client->setAuthConfig('service_account.json');
$client->setApplicationName("gtmdocx");
/*$client->setScopes(['https://www.googleapis.com/auth/tagmanager.readonly',
'https://www.googleapis.com/auth/tagmanager.manage.accounts',
'https://www.googleapis.com/auth/tagmanager.edit.containers']);*/
$client->setScopes(['https://www.googleapis.com/auth/tagmanager.readonly']);
$service = new Google_Service_TagManager($client);
$results = $service->accounts->listAccounts();
echo $_GET['callback'] . '('.json_encode($results).')';
I had exactly this problem using the Google Drive app, after hours trying to find a solution, I got it to work using the GuzzleHttp sink option
$client = new \Google_Client();
// ... Client Configuration
$httpClient = new Client([
'sink' => 'path_to_any_temp_file',
'base_uri' => $client->getConfig('base_path'),
]);
$client->setHttpClient($httpClient);
Worth the try.
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.
I am trying to get the content of WSDL from HTTPS Server
<?php
echo file_get_contents("https://zendsoap.lan/Zend_Soap_Server.php?wsdl");
?>
It Return:
Warning: file_get_contents() [function.file-get-contents]: SSL operation failed with code 1. OpenSSL Error messages: error:1408E0F4:SSL routines:func(142):reason(244) in /Applications/AMPPS/www/zendSoap.lan/Zend_Soap_Client.php on line 4
Warning: file_get_contents() [function.file-get-contents]: Failed to enable crypto in /Applications/AMPPS/www/zendSoap.lan/Zend_Soap_Client.php on line 4
Warning: file_get_contents(https://zendsoap.lan/Zend_Soap_Server.php?wsdl) [function.file-get-contents]: failed to open stream: operation failed in /Applications/AMPPS/www/zendSoap.lan/Zend_Soap_Client.php on line 4
AND when I can goto the WSDL Location (https://zendsoap.lan/Zend_Soap_Server.php?wsdl): Everything looks fine.
P.S: Can anybody tell me how can I share the WSDL file
I agree with RockyFord regarding it being an SSL issue (I'm pretty sure you will have a self signed certificate in place and due to using SSL there are a few steps you will need to take in order to minimise security concerns). Regarding the immediate issue you could try fixing it with code similar to this:
$url = 'https://zendsoap.lan/Zend_Soap_Server.php?wsdl';
$contextOptions = array(
'ssl' => array(
'verify_peer' => true,
'CN_match' => 'zendsoap.lan' // assuming zendsoap.lan is the CN used in the certificate
)
);
$sslContext = stream_context_create($contextOptions);
$wsdlContent = file_get_contents($url, NULL, $sslContext);
(UPDATE: It might seem like an easy solution to change the code above to
'verify_peer' => false
while it may be ok for basic development it's not really a good idea and definitely shouldn't be used in a production environment as it introduces serious security concerns - see this excellent article on How to properly secure remote API calls over SSL from PHP code by Artur Ejsmont for more on this subject as well as the Transport Layer Security Cheat Sheet and Securing Web Services by OWASP)
To pick up on your point regarding sharing a WSDL from within a Zend Framework application you could do something like this to get started:
// go to application/configs/application.ini
// if your APPLICATION_ENV is development then add the following line in the development section:
phpSettings.soap.wsdl_cache_enabled = 0
The line above will prevent your wsdl being cached during development. Next you might want to create a SoapController and add this action like this:
public function serverAction()
{
$baseUrl = 'http://zendsoap.lan/soap/server';
if( isset( $_GET['wdsl'] ) ) {
$strategy = new Zend_Soap_Wsdl_Strategy_AnyType();
$server = new Zend_Soap_AutoDiscover($strategy);
$server->setUri($baseUrl);
$server->setClass('Application_Model_Web_Service');
$server->handle();
} else {
$server = new Zend_Soap_Server($baseUrl . '?wsdl');
$server->setClass('Application_Model_Web_Service');
$server->handle();
}
}
The nice thing about the approach above is the WSDL will be generated for you on the fly. You will have noticed the setClass() method is going to be called with 'Application_Model_Web_Service' passed as the only parameter. To test your configuration I recommend you create that class and insert the method below. Testing your configuration with a simple service containing a single method will help you with troubleshooting before you make the service more complex. Here is the example method:
// Note: you should definitely comment your methods correctly in the class so
// the WSDL will be generated correctly - by that I mean use #param and #return
// so the correct input and output types can be determined and added to the WSDL
// when the the ZF component generates it for you
/**
* #return string
*/
public function getMessage()
{
return 'ok';
}
(UPDATE: Also in response to the question you asked regarding using Zend_Soap_Client to access the web service, since it looks like you're intending to make it a secure service I'd suggest you raise a separate question regarding setting up secure soap services with php. If you explain more about what you're trying to do in that question you may get some good input from a range of experts on best practices :-)
)
I know you're new to SO so if you're happy with the answer you can accept it, also generally it's best to just reply to an answer rather than add another answer to reply. Easy when you know how of course and even easier when someone tells you ;-)
I tried your way of defining The Soap Server, only thing was I used my custom class instead of using Application_Model_Web_Service. I am using single files for Client & Server. When I run https://zendsoap.lan/Zend_Soap_Server.php without ?wsdl it result in this:
<SOAP-ENV:Envelope>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>WSDL</faultcode>
<faultstring>SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://zendsoap.lan/Zend_Soap_Server.php?wsdl' : failed to load external entity "https://zendsoap.lan/Zend_Soap_Server.php?wsdl"
</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
And When I try file_get_contents() the way you told, I get this:
Warning: file_get_contents() [function.file-get-contents]: SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:func(144):reason(134) in /Applications/AMPPS/www/zendSoap.lan/https_soap_test.php on line 16
Warning: file_get_contents() [function.file-get-contents]: Failed to enable crypto in /Applications/AMPPS/www/zendSoap.lan/https_soap_test.php on line 16
Warning: file_get_contents(https://zendsoap.lan/Zend_Soap_Server.php?wsdl) [function.file-get-contents]: failed to open stream: operation failed in /Applications/AMPPS/www/zendSoap.lan/https_soap_test.php on line 16
Here is link to screenshot of My Certificate:
http://i.stack.imgur.com/bKoVD.png
Loads of thanks for your help.
Problem solved By changing 'verify_peer' => false
Can you (#dkcwd) please tell me what should be the code if I use Zend_Soap_Client without file_get_contents(). I mean is there any option which i can't find on internet to do something similar to 'verify_peer' => false.
Loads of Thanks to #dkcwd
UPDATE: Let me summarise what exactly I am doing, I am trying to create a basic SOAP Server over SSL. Before making Web Services available on my Production website, I have to test it on Development system with has got Self Signed Certificate (Whose authentication is a problem right now).
Following are the problems I am facing in that regard:
When I try to call https://zendsoap.lan/Zend_Soap_server.php?wsdl its works fine I can view the wsdl.
But when I try https://zendsoap.lan/Zend_Soap_server.php, I get this:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://zendsoap.lan/Zend_Soap_Server.php?wsdl' : failed to load external entity "https://zendsoap.lan/Zend_Soap_Server.php?wsdl"
Is that something I should be
The reason I made verify_peer=>false as I am running it on dev server so no need to verify my own created certificate, but obviously on production I want the Certificate to be verified.
This thing work fine with NuSoap but most of the stuff in NuSoap is deprecated for our server which is running PHP 5.4.6, So the most reliable solution for me using PHP's SOAP extension. And the reason for me using Zend is we're in process of moving our system from some third party framework to Zend Framework and everyday I get requests from client to add this & that new components, I assumed if I develop every new request from Client using Zend libraries then it will be easy for me in later stages to move to Zend Framework.
I hope I made some sense there.
Many Thanks in advance...
i keep getting an stupid error in PHP related to SOAP which i can't solve. I've searched quite much via Google and in the official manual, but there is nothing helpful for me.
This is my problem: I got an official endpoint adress: $wsdl = example.com/wsdl, which i need to use for an soap request. The problem is that there is an proxy at my university trying to destroy all my work. So in general i need to get past my proxy, then access the wsdl file successfully and then authenticate at the web service.
What i have tried:
$wsdl = "example.com/wsdl";
$client = new SoapClient($wsdl,array('user' => 'username','password' => 'password'));
This throws the error:
"SOAP-ERROR: Parsing WSDL: Couldn't load from ... : failed to load external entity"
I also tried to cache the external wsdl file via file_get_contents by creating an valid stream with stream_context_create() which also resulted in the same error message.
How can i access this thing now? What am i doing wrong?