Facebook.php causes error in apache log, how to fix? - facebook

I have a Facebook application running on Amazon servers (windows data center + apache) and this shows up in the apache error log a lot:
"Invalid or no certificate authority found, using bundled information"
In facebook.php the error is generated here:
if ((curl_errno($ch) == 60) || (curl_errno($ch) == 77)) { // CURLE_SSL_CACERT || CURLE_SSL_CACERT_BADFILE
self::errorLog('Invalid or no certificate authority found, using bundled information');
curl_setopt($ch, CURLOPT_CAINFO,
dirname(__FILE__) . '/fb_ca_chain_bundle.crt');
$result = curl_exec($ch);
}
I have the latest fb_ca_chain_bundle.crt from github in the same directory.

Download facebook.php and the fb_ca_chain_bundle.crt certificate again and replace them with your current files.

Related

Magento 2 - Custom rest api endpoint for PDF download - net::ERR_HTTP2_PROTOCOL_ERROR 200

I have created custom rest api endpoint in magento for downloading pdf file.
When testing it locally: From separate react JS project I am sending request to that endpoint and file is downloaded successfuly. http/1.1 protocol is used (checked in google chrome dev tools, network tab).
After deployment to staging servers, when I try to make request between staging servers from reactJS project to magento2 project, then upon sending request it takes 30-40 seconds without getting any response and then error is shown in console. There is not anything in the error logs. http2 protocol is used (not sure if that can be a reason for issue).
Failed to fetch - net::ERR_HTTP2_PROTOCOL_ERROR 200
Here is the piece of php code for downloading pdf file:
...
$filename = $outputFileName . time() . '.' . $extension;
$directoryTmpWrite = $this->filesystem->getDirectoryWrite(DirectoryList::TMP);
$directoryTmpWrite->writeFile($filename, $fileContent);
return $this->fileFactory->create(
$outputFileName . '.' . $extension,
[
'type' => 'filename',
'value' => $filename,
'rm' => true,
],
DirectoryList::TMP, //basedir
'application/octet-stream',
''
);
How I resolved my issue?
I had to turn on output buffering in php in magento, to ensure that no output has been sent from a script and instead of that output has been store to a buffer and then sent all together from a script when script execution is finished.
So ob_start() fixed my issue. Right before return statement.

Neteller REST API gives an error

I've been working with neteller rest api and I came across an issue.
I am receiving this response: { "error": "invalid_client" }
My code is
$username = '**********';
$password = '*********************************';
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_URL, "https://test.api.neteller.com/v1/oauth2/token?grant_type=client_credentials");
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type:application/json", "Cache-Control:no-cache"));
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$serverOutput = curl_exec($curl);
echo $serverOutput;
The documentation says:
Client authentication failed (e.g., unknown client, no client authentication included, or
unsupported authentication method). The authorization server MAY return an HTTP 401
(Unauthorized) status code to indicate which HTTP authentication schemes are
supported. If the client attempted to authenticate via the "Authorization" request header
field, the authorization server MUST respond with an HTTP 401 (Unauthorized) status
code and include the "WWW-Authenticate" response header field matching the
authentication scheme used by the client.
But I'm not sure I completely understand this..
I've tried every possible solution that I found online, but nothing works.. Is there something wrong with my CURL?
Thanks for your time.
You get this error message if your IP is blocked. Log in to the Neteller TEST merchant site (test.merchant.neteller.com). You will need to email support to get a user if you haven't already. Go to Developer / API Settings and check that the APIs are enabled and that your IPs are added.
You need to do the same thing for production (merchant.neteller.com).
It might be a header issue.
Try this as your content type:
application/x-www-form-urlencoded
This should probably solve it:
$data = array("scope" => "default");
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

Dwolla Balance Error 307

I'm using the official Dwolla PHP Library and trying:
$balance = $Dwolla->balance();
if(!$balance) { echo "Error: {$Dwolla->getError()} \n"; } else {
echo "Balance: $balance";}
as referenced in the Dwolla Developer Documentation, and getting:
"Request Failed. Server responded with: 307"
I know I have appropriate Oauth permissions, and if that's an HTTP response, then I believe it's a temporary redirect. What am I missing?
This was fixed in the PHP library...

Warning: file_get_contents(https://graph.facebook.com/me?access_token=)

Warning: file_get_contents(https://graph.facebook.com/me?access_token=) [function.file- get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in /var/www/dsg/signed_request.php on line 25
I have checked and set allow_url_fopen to on in my php.ini and also made sure allow_url_fopen is on when I run phpinfo();. I am still getting the error as listed above. Does anyone know if this can be made to work somehow? Perhaps has some converted to an alternative?
You can use curl, which is actually what should be used for network requests, not file_get_contents. I don't know why Facebook started using that function in there examples. Curl has error handling and will follow redirects if you want it to, so you can figure out exactly what is happing.
You can create your own one line function like this
function viacurl($location){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $location);
curl_setopt($ch, CURLOPT_HEADER, false);
$out=curl_exec($ch);
curl_close($ch);
return rtrim($out,1);
}
And use it like this :
$response = viacurl($url);

why can't I connect to apple push notification service?

I have meet a big problem when I was doing developing about Apple Push Notification Service.
I wrote a PHP script(apns.php) which will use a PEM(ck.pem) file as security certificate and build a SSL connection to APNS when I post a HTTP request to it, but it always failed when it tried to connect the service port ( ssl://gateway.sandbox.push.apple.com:2195). The PHP script is deployed on a Linux Hosting of GoDaddy (it should support SSL).
I have already registered to be a member of iOS developer program,and I have registered the apple push notification service for my application. And I have generated a certificate file and a key file (cert.p12 and key.p12) from Keychain Access and translate them into PEM files(cert.pem and key.pem) and join them into one(ck.pem) and put it in the same directory of PHP script .
I want to know if there is something wrong I did ! Would you refer to the attachment of the files that you may need?
Thanks very much!
The HTTP request is something like below.
http://www.insidertracker.net/apns/apns.php?message=&badge=2&sound=received5.caf
The response message of my request is below:
Warning: stream_socket_client() [function.stream-socket-client]:
unable to connect to ssl://gateway.sandbox.push.apple.com:2195
(Connection refused) in /home/content/40/6967940/html/apns/apns.php on
line 25 Failed to connect 111 Connection refused
The PHP script:
<?php
$deviceToken = '0535dda1 6fd04e87 ed0a8194 d418a6c1 99eec462 8a871891 d062018d c6af4f99';
$pass = 'Php1234'; // Passphrase for the private key (ck.pem file)
// Get the parameters from http get or from command line
$message = $_GET['message'] or $message = $argv[1] or $message = 'You have an important message from InsiderTracker';
$badge = (int)$_GET['badge'] or $badge = (int)$argv[2];
$sound = $_GET['sound'] or $sound = $argv[3];
// Construct the notification payload
$body = array();
$body['aps'] = array('alert' => $message);
if ($badge)
$body['aps']['badge'] = $badge;
if ($sound)
$body['aps']['sound'] = $sound;
/* End of Configurable Items */
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
// assume the private key passphase was removed.
stream_context_set_option($ctx, 'ssl', 'passphrase', $pass);
// connect to apns
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
// $fp = fsockopen('ssl://gateway.sandbox.push.apple.com:2195', 2195, $err, $errstr, 30);
if (!$fp) {
print "Failed to connect $err $errstr\n";
return;
}
else {
print "Connection OK\n<br/>";
}
// send message
$payload = json_encode($body);
$msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack ("n",strlen($payload)) . $payload;
print "Sending message :" . $payload . "\n";
fwrite($fp, $msg);
fclose($fp);
?>
It's my understanding that GoDaddy prohibits outgoing connections on exotic ports (anything other than 80 a perhaps a few others). You're probably out of luck trying to roll your own push service hosted on GoDaddy. I have had luck doing what you're attempting with bluehost.
For general advice on developing a push service in PHP, these two articles were invaluable: One Two
I also got this error. Following things you have to remember:
Path of ios push cert file should be correct. Check on online portals using device token and push cert.
Your server is enabled for 2195 port. Check on terminal by using telnet command.
Check ssl supported by your php version if using ssl://gateway.sandbox.push.apple.com and tls if using tls://gateway.sandbox.push.apple.com
The data you are sending in the push or token etc should be equal or less than the specified bytes mentioned in the apple doc. link is mentioned below.
You can also use api get reference for sending push Development server: api.development.push.apple.com:443 Production server: api.push.apple.com:443
https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html#//apple_ref/doc/uid/TP40008194-CH11-SW1