Facebook PHP SDK "couldn't connect to host" - facebook

I'm trying to connect to facebook API
require_once '/composer/vendor/autoload.php';
$fb = new Facebook\Facebook([
'app_id' => 'xxxx', // obviously, I've put my app ID in here
'app_secret' => 'xxxx', // and my app secret in here
'default_graph_version' => 'v2.4',
]);
To do the following request, which, if I'm right, should give me the number of shares of the URL :
$target = 'http://stackoverflow.com';
$node = $fb->get('/?id='.urlencode($target).'&fields=share')->getGraphNode();
$shareCount = $node['share']['share_count'];
However, I get the following error :
Fatal error:
Uncaught exception 'Facebook\Exceptions\FacebookSDKException'
with message 'couldn't connect to host'
in /backend/composer/vendor/facebook/php-sdk-v4/src/Facebook/HttpClients/FacebookCurlHttpClient.php:83
Stack trace:
#0 /backend/composer/vendor/facebook/php-sdk-v4/src/Facebook/FacebookClient.php(216):
Facebook\HttpClients\FacebookCurlHttpClient->send('https://graph.f...', 'GET', '', Array, 60)
#1 /backend/composer/vendor/facebook/php-sdk-v4/src/Facebook/Facebook.php(504):
Facebook\FacebookClient->sendRequest(Object(Facebook\FacebookRequest))
#2 /backend/composer/vendor/facebook/php-sdk-v4/src/Facebook/Facebook.php(377):
Facebook\Facebook->sendRequest('GET', '/?id=http%3A%2F...', Array, NULL, NULL, NULL)
#3 /backend/the_script_i_am_currently_trying_to_run.php(79):
Facebook\Facebook->get('/?id=http%3A%2F...')
#4 {main} thrown in /backend/composer/vendor/facebook/php-sdk-v4/src/Facebook/HttpClients/FacebookCurlHttpClient.php on line 83
From what I have read, it could be that I'm not allowed to use cURL on my server, but I'm using it somewhere else and it works, so I don't think the problem comes from here.
Any idea of what I'm doing wrong ?
Thanks

Related

Zend Framework 2 Zend_Http_Client SSL Connection Error

i want to parse all kinds of ssl/https Sites.
E.g i want the content of https://microsoft.de, but it do not work. Following Erros appears:
Fatal error: Uncaught exception 'ErrorException' with message 'stream_socket_enable_crypto() [<a href='function.stream-socket-enable-crypto'>function.stream-socket-enable-crypto</a>]:
SSL operation failed with code 1.
OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed'
in C:\Users\Privat\Desktop\Server\Apache2\htdocs\allsubmitter\server\vendor\zendframework\zend-http\Zend\Http\Client\Adapter\Socket.php:276
Stack trace: #0 [internal function]: Zend\Stdlib\ErrorHandler::addError(2, 'stream_socket_e...', 'C:\Users\Privat...', 276, Array) #1 C:\Users\Privat\Desktop\Server\Apache2\htdocs\allsubmitter\server\vendor\zendframework\zend-http\Zend\Http\Client\Adapter\Socket.php(276): stream_socket_enable_crypto(Resource id #35, true, 2)
#2 C:\Users\Privat\Desktop\Server\Apache2\htdocs\allsubmitter\server\vendor\zendframework\zend-http\Zend\Http\Client.php(1356): Zend\Http\Client\Adapter\Socket->connect('microsoft.de', 443, true) #3 C:\Users\Privat\Desktop\Server\Apache2\htdocs\ in C:\Users\Privat\Desktop\Server\Apache2\htdocs\allsubmitter\server\vendor\zendframework\zend-http\Zend\Http\Client\Adapter\Socket.php on line 299
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Socket',
'ssltransport' => 'tls'
);
$client = new \Zend\Http\Client("https://microsoft.de");
You can tell the client not to verify the SSL, try this config:
$clientConfig = array(
'adapter' => 'Zend\Http\Client\Adapter\Curl',
'curloptions' => array(
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_SSL_VERIFYPEER => FALSE
),
);
$this->_client = new \Zend\Http\Client('https://microsoft.de', $clientConfig);

mblox soap api - php soap Payment Request not working

mblox soap api - php soap Payment Request not working and gives error.
I use as below code in subscribe.php file...
$client = new SoapClient("https://ngp.us.mblox.com/client-gateway/services?wsdl", array('trace' => 1, 'encoding' => 'UTF-8', 'soap_version' => SOAP_1_2));
$array = array(
'SecurityContext'=>array('userId'=>'aaaaaaaa','password'=>'bbbbbbbb'),
'ClientDetails'=>array('shortcode'=>'234242', 'brandName'=>'aaaaaaaaaa.com', 'programSponsor'=>'aaaaaaaaaa', 'originatingUrl'=>'www.aaaaaaaaaa.com', 'minPageUrl'=>'www.aaaaaaaaaa.com', 'successUrl'=>'www.aaaaaaaaaa.com/subscribConfirm.php', 'cancelUrl'=>'www.aaaaaaaaaa.com', 'tcUrl'=>'www.aaaaaaaaaa.com/terms.html', 'postBackUrl'=>'http://aaaaaaaaaa/subscribe.php'),
'paymentDetails'=>array('paymentType'=>'PSMS', 'amount'=>'9.99', 'currency'=>'USD', 'billingFrequency'=>'MONTHLY'),
'msisdn'=>'243233232',
'serviceId'=>'332',
'operatorId'=>'33343',
'productDescription'=>'Text test',
'optInBody'=>'aaaaaaaaaa',
'browserSessionId'=>'123456',
);
$result = $client->initiatePayment($array);
It shows error as below on last line => $result = $client->initiatePayment($array);
Fatal error: Uncaught SoapFault exception: [(null)] in
/aaaaaaaa/Source/developement/PHP/ver1/subscribe.php:97 Stack trace:
0 /aaaaaaaa/Source/developement/PHP/ver1/subscribe.php(97): SoapClient->__call('initiatePayment', Array) #1
/aaaaaaaa/Source/developement/PHP/ver1/subscribe.php(97):
SoapClient->initiatePayment(Array) #2 {main} thrown in
/aaaaaaaa/Source/developement/PHP/ver1/subscribe.php on line 97
I got things working using curl,
I use This
as a reference and code working.
Thankx

Google authentication

I got a problem on google authenticate, it worked for a month but since a few days I got this error :
Fatal error: Uncaught exception 'apiAuthException' with message
'Invalid token format' in /home/project/html/google/auth/apiOAuth2.php:127 Stack trace:
#0 /home/project/html/google/auth/apiOAuth2.php(89): apiOAuth2->setAccessToken('{? "access_tok...')
#1 /home/project/html/google/apiClient.php(132): apiOAuth2->authenticate(Array)
#2 /home/project/html/hk/connects/google.php(22): apiClient->authenticate()
#3 {main} thrown in /home/project/html/google/auth/apiOAuth2.php on line 127
In apiOAuth2.php I have the code :
$accessToken = json_decode($accessToken, true);
if (! isset($accessToken['access_token']) || ! isset($accessToken['expires_in']) || ! isset($accessToken['refresh_token'])) {
throw new apiAuthException("Invalid token format");
}
I noticed that google doesn't send me the $accessToken['refresh_token'].
It doesn't seem to come from google cause I did a correct connexion on http://stackoverflow.com
Maybe it's cause of my code :
session_start();
$client = new apiClient();
$plus = new apiPlusService($client);
if (!isset($_GET['code'])) {
header('Location: '.$client->createAuthUrl()); // Calls the same page
} else {
$client->authenticate(); // Fails at this level
}
EDIT:
I figured a way to do it, like I don't know what is refresh_token made for I added this line :
if (!isset($accessToken['refresh_token'])) $accessToken['refresh_token'] = 12345678910;
It works for the moment...
There is a new explicit parameter called "access_type" required by the google authentication api to obtain a valid refresh token.
With this parameter you declare that you need offline access to the account and the api provides you a refresh token.
Download the latest google PHP SDK that automatically handles the new required parameter

Zend Mail keeps giving me a Socket Error

I'm having trouble with sending email using the zend framework. I keep getting a "Could not open socket" error.
I don't know whats wrong here - it used to work on my other host. Ever since I shifted it to another host I can't send emails. I've set up the configuration values to match the new email server.
Heres my code:
$config = array('auth' => _config('mail', 'auth'),
'username' => _config('mail', 'email'),
'password' => _config('mail', 'password'));
$tr = new Zend_Mail_Transport_Smtp(_config('mail', 'smtp'), $config);
$mail = new Zend_Mail();
$mail->setDefaultTransport($tr);
$mail->setFrom(_config('mail','email'), _config('mail','name'));
$mail->addTo($account_email);
$mail->setSubject($mailTitle);
$mail->setBodyText($mailContent);
$mail->send($tr);
EDIt ===
Well the code posted above is my actual code - I don't know whats wrong with it as it used to work on another host.
The following is the exact error I'm getting
Could not open socketstring(1237) "#0 /home/india/public_html/demo/library/Zend/Mail/Protocol/Smtp.php(167): Zend_Mail_Protocol_Abstract->_connect('tcp://mail.indi...')
#1 /home/india/public_html/demo/library/Zend/Mail/Transport/Smtp.php(199): Zend_Mail_Protocol_Smtp->connect()
#2 /home/india/public_html/demo/library/Zend/Mail/Transport/Abstract.php(348): Zend_Mail_Transport_Smtp->_sendMail()
#3 /home/india/public_html/demo/library/Zend/Mail.php(1194): Zend_Mail_Transport_Abstract->send(Object(Zend_Mail))
#4 /home/india/public_html/demo/application/controllers/AccountController.php(2153): Zend_Mail->send(Object(Zend_Mail_Transport_Smtp))
#5 /home/india/public_html/demo/library/Zend/Controller/Action.php(513): AccountController->forgetPasswordAction()
#6 /home/india/public_html/demo/library/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action->dispatch('forgetPasswordA...')
#7 /home/india/public_html/demo/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#8 /home/india/public_html/demo/application/bootstrap.php(26): Zend_Controller_Front->dispatch() #9 /home/india/public_html/demo/html/index.php(4): Bootstrap::run() #10 {main}"
marhaba Ali! ,
digging the code of Zend mail shows http://framework.zend.com/svn/framework/standard/trunk/library/Zend/Mail/Protocol/Abstract.php
protected function _connect($remote)
{
$errorNum = 0;
$errorStr = '';
// open connection
$this->_socket = #stream_socket_client($remote, $errorNum, $errorStr, self::TIMEOUT_CONNECTION);
if ($this->_socket === false) {
if ($errorNum == 0) {
$errorStr = 'Could not open socket';
}
/**
* #see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception($errorStr);
}
if (($result = $this->_setStreamTimeout(self::TIMEOUT_CONNECTION)) === false) {
/**
* #see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('Could not set stream timeout');
}
return $result;
}
and usually the error number 0 because of
if ($errorNum == 0) {
$errorStr = 'Could not open socket';
}
from : http://php.net/manual/en/function.stream-socket-client.php
On failure the errno and errstr
arguments will be populated with the
actual system level error that
occurred in the system-level connect()
call. If the value returned in errno
is 0 and the function returned FALSE,
it is an indication that the error
occurred before the connect() call.
This is most likely due to a problem
initializing the socket. Note that the
errno and errstr arguments will always
be passed by reference.
I guess its some firewall blocking the connection to be sent out ,
system-level or network-level error
If you update your answer with more detailed info , i would be happy to help

Zend_Log with mail

Has anyone succeed to send an mail(SMTP GOOGLE) with Zend_Log.I found this http://framework.zend.com/manual/en/zend.log.writers.html
Chapter 32.2.4. Writing to Email but by default it's using mail(), but I want to use SMTP.So until now my code looks like this:
$mailconf = array('ssl'=>'ssl',
'auth' => 'login',
'username' => 'mymail#gmail.com',
'password' => 'mypass',
'port'=>'465');
$transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $mailconf);
$mail = new Zend_Mail();
$mail->setFrom('from.website#example.com')
->addTo('mysecondmail#site.com');
$writer = new Zend_Log_Writer_Mail($mail);
// On fixe le sujet du mail
$writer->setSubjectPrependText('Important Log Events');
// Only email warning level entries and higher.
$writer->addFilter(Zend_Log::WARN);
$loggerZendMail = new Zend_Log();
$loggerZendMail->addWriter($writer);
$loggerZendMail->log('unable to connect to database',Zend_Log::WARN);
I'm getting this error:
Fatal error: Uncaught exception 'Zend_Log_Exception' with message 'Unable to send mail' in C:\wamp\www\zf_log\Zend\Log\Writer\Mail.php:256 Stack trace: #0 C:\wamp\www\zf_log\Zend\Log.php(84): Zend_Log_Writer_Mail->shutdown() #1 C:\wamp\www\zf_log\Zend\Controller\Action.php(512): Zend_Log->__destruct() #2 C:\wamp\www\zf_log\Zend\Controller\Action.php(512): IndexController->indexAction() #3 C:\wamp\www\zf_log\Zend\Controller\Dispatcher\Standard.php(288): Zend_Controller_Action->dispatch('indexAction') #4 C:\wamp\www\zf_log\Zend\Controller\Front.php(945): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #5 C:\wamp\www\zf_log\index.php(30): Zend_Controller_Front->dispatch() #6 {main} thrown in C:\wamp\www\zf_log\Zend\Log\Writer\Mail.php on line 256
Any suggestions?
You need to set the transport for Zend_Mail to use
Example:
Zend_Mail::setDefaultTransport($transport);
I would check if SMTP is enabled on server.
Use TLS instead of SSL also check if the port 587 works
so the below config should work
$mailconf = array('ssl'=>'tls', 'auth' => 'login', 'username' => 'mymail#gmail.com', 'password' => 'mypass', 'port'=>'587');