The attempt to establish a connection with graph.facebook.com on port 443 was unsuccessful due to connection refusal

I am completely new to integrating the FB graph API into my website and have been following the official FB login tutorial provided on their website. Despite following the steps, I encountered this error after attempting to log in:

Failed to connect to graph.facebook.com port 443: Connection refused

In my login.php file:

<?php
session_start();
require_once __DIR__ . '/fbsdk/src/Facebook/autoload.php';

$fb = new Facebook\Facebook([
'app_id' => 'xxx',
'app_secret' => 'xxx',
'default_graph_version' => 'v2.3',
// . . .
]);

$helper = $fb->getRedirectLoginHelper();
$permissions = ['public_profile', 'email']; // optional
$loginUrl = $helper->getLoginUrl('http://-myserver-/login-callback.php',    $permissions);

echo '<a href="' . $loginUrl . '">Log in with Facebook!</a>';
?>

Inside my login-callback.php file:

<?php
session_start();
require_once __DIR__ . '/fbsdk/src/Facebook/autoload.php';

$fb = new Facebook\Facebook([
'app_id' => 'xxx',
'app_secret' => 'xxx',
'default_graph_version' => 'v2.3',
// . . .
]);

$helper = $fb->getRedirectLoginHelper();
try {
$accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// Handling Graph errors
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// Handling SDK errors
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}

if (isset($accessToken)) {
// Successfully logged in!
$_SESSION['facebook_access_token'] = (string) $accessToken;

// Redirecting to another page and utilizing the access token from $_SESSION['facebook_access_token']
}
?>

And in my example-canvas-app.php file:

<?php
session_start();
require_once __DIR__ . '/fbsdk/src/Facebook/autoload.php';

$fb = new Facebook\Facebook([
'app_id' => 'xxx',
'app_secret' => 'xxx',
'default_graph_version' => 'v2.3',
// . . .
]);

$helper = $fb->getCanvasHelper();
try {
$accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// In case of a Graph error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// Handling validation failures or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}

if (isset($accessToken)) {
// User has successfully logged in.
}
?>

I've tried searching extensively on Stack Overflow and Google for a solution, but unfortunately, haven't found one yet.

Answer №1

Hostinger's customer service confirmed that their free server does not support a connection to Facebook's SDK.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

In PHP, implement a function to insert a delimiter into a string retrieved from a

Merchant Id|Merchant|Website|Transaction In Period|Voids In Period|Gross Sales Amount|Total Commision in Period 9766|Mountains Plus Outdoor Gear|www.MPGear.com|1|0|88.91|8.89 12447|Meritline.com|www.meritline.com|5|0|52.86|3.71 16213|East Coas ...

Posts that have already been viewed

Currently, I am in the process of working on a forum and it's nearing completion. However, I have hit a roadblock that is proving to be quite challenging. If you're familiar with the phpBB forum, you may know about a feature that distinguishes p ...

Strip out any HTML code from scraped content that does not contain an identifier or class

I am seeking a way to eliminate specific html code from the data I am scraping, however, I am unable to isolate it by its id or class. It is necessary to erase every occurrence of this particular code within the html. <ul data-bfa="@l:Subbuzz-Sha ...

Updating data in MySql database using Laravel framework

I'm facing an issue while trying to update my SQL table in Laravel. The problem is that it changes the page but fails to reflect the update in the database. I need the form to trigger a database refresh after clicking on the "Atualizar" button. Route ...

Managing the initial record in mysql

As I work on a slideshow, my goal is to dynamically change the HTML class attribute from "item" to "item active" when the first record is fetched from the database. For all subsequent records, the class should revert back to just "item." $RelatedTo=1; $ ...

Do not need to refresh the form

I developed a PHP-based Feedback form that includes a Popup from Foundation 5. <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <style type="text/css"> .auto-style1 { margin-left: 1px; ...

Utilizing Laravel to send an ajax request to a controller

I am encountering a strange issue with the response from my ajax request. The controller's method below is supposed to return an ID: <?php namespace App\Http\Controllers; use Illuminate\Http\Request; //use App\Http&bsol ...

storing the output of print_r in a variable

When using PHP, I've mastered: print_r($var); However, one thing that stumps me (or at least I haven't figured out yet) is: $var_info = print_r($var); My goal is to store the output of a print_r function in a variable. Any ideas on how to ach ...

Splitting a string into multiple parts in PHP

I am working with a string stored in $buffer that contains three pieces of information tweetid category tweet for example: 123432 politics 'this is a political tweet' I am trying to separate this string into individual parts, where 123432 is ...

Testing the object created by a factory with unit tests

I am currently working on writing a unit test for a Factory class, but when I run the test with PHPUnit, it throws a fatal error regarding the creation of the Product. Fatal error: Class 'JsonStorage' not found Directory Structure -\ ...

The database powered by Postgresql performs flawlessly when it comes to updating data with accurate code execution. However, there seems to be an

Imagine a zoo with a postgresql database. To enable web access to this database, I am using php and javascript. Most of the web pages are working fine, but I am currently working on a page where clients can add or remove animals from existing exhibits. T ...

Triggering events in server-side scripts involves activating specific actions to occur

Websites like SO have a feature where you receive notifications when your question gets answered, or when you earn a new badge. Additionally, if you receive a new private message in the forum, you are notified with an alert message. Whe ...

PHP scripting combined with AJAX technology can be used to effortlessly insert data

Hey everyone, I'm currently diving into the world of coding and facing an issue with an ajax/php script. My goal is to insert data into a database without having to refresh the page. Below is the code I've been working on: <?php require(&apo ...

Obtain the longitude and latitude coordinates by calculating the distance and angle

I need to generate geographical combinations within a grid that covers my city. The grid measures 500m x 500m. I want to input starting longitude/latitude coordinates, distance (500m), degree (90 or 270), and receive the next longitude/latitude combination ...

Trouble retrieving data from an array in Angular locally

No matter how hard I tried, fetching data from MySQL, H2, and Derby databases seemed impossible. Following the instructions on w3schools website didn't yield any results. However, a light bulb went off in my head and I decided to give the Array Functi ...

What is the proper way to store the current date in a variable using the getdate() function?

When using the getdate() function to store the date in a variable, I am encountering an issue. Can someone point out what mistake I might be making? $currentDate = getdate(); echo "Today's date is ".$currentDate; Output: The current date displays a ...

Generate your own unique referral links today

Searching for ways to generate and monitor referral links like www.domain.com/?ref=switz What steps should I take to accomplish this? ...

Combining two associative arrays in PHP

I am facing an issue with two separate arrays. Array 1: Array ( [0] => Array ( [id] => 1 [name] => Product 1 [quantity] => 2 [unit_amount] => Array ( ...

The Google reCaptcha reply was "Uncaught (in promise) null"

When using reCaptcha v2, I encountered an issue in the developer console showing Uncaught (in promise) null message regardless of moving the .reset() function. Here is the console output: https://i.stack.imgur.com/l24dC.png This is my code for reCaptcha ...

Issue Encountered While Executing Laravel's Artisan Command

Having just started exploring Laravel, I'm facing a minor issue that I need some help with. Initially, I successfully created a basic template and ran it using phpMyAdmin on Wamp without any problems. However, when I was tasked with reviewing an older ...