Click here to Skip to main content
15,885,546 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
GeneralRe: Get the html content from a website using php Pin
Joshin Joy18-Dec-17 20:15
Joshin Joy18-Dec-17 20:15 
GeneralRe: Get the html content from a website using php Pin
Jochen Arndt18-Dec-17 21:02
professionalJochen Arndt18-Dec-17 21:02 
GeneralRe: Get the html content from a website using php Pin
Member 1387615717-Jun-18 20:01
Member 1387615717-Jun-18 20:01 
Questionfunction to display content with php does not work as intended Pin
CHrispho15-Dec-17 9:46
CHrispho15-Dec-17 9:46 
AnswerRe: function to display content with php does not work as intended Pin
Jochen Arndt17-Dec-17 22:50
professionalJochen Arndt17-Dec-17 22:50 
QuestionChat functionality is not working when SSL is involved Pin
Member 135528281-Dec-17 17:15
Member 135528281-Dec-17 17:15 
AnswerRe: Chat functionality is not working when SSL is involved Pin
jschell5-Dec-17 12:29
jschell5-Dec-17 12:29 
QuestionPHP: using Facebook login SDK returned an error: No URL set! Pin
iucaa19-Nov-17 22:53
iucaa19-Nov-17 22:53 
Good evening, I'm trying to implement access to our site using Facebook sdk (Ver. 5x PHP 5.6), I always get the following
error "Facebook SDK returned an error: No URL set!"
the code I use works fine in another test site (obviously with a different facebook app and secret keys), i really don't know where is the problem Frown | :( I post sources:

This is the index.php code where the button for the login and the call of SDK appears, for obvious security reasons I entered xxxx instead of the site name and other sensitive data.

PHP
// index.php
require_once 'fbConfig.php';
require_once 'User.php';

if(isset($accessToken)){
if(isset($_SESSION['facebook_access_token'])){
$fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
}else{
// Put short-lived access token in session
$_SESSION['facebook_access_token'] = (string) $accessToken;

// OAuth 2.0 client handler helps to manage access tokens
$oAuth2Client = $fb->getOAuth2Client();

// Exchanges a short-lived access token for a long-lived one
$longLivedAccessToken = $oAuth2Client->getLongLivedAccessToken($_SESSION['facebook_access_token']);
$_SESSION['facebook_access_token'] = (string) $longLivedAccessToken;

// Set default access token to be used in script
$fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
}

// Redirect the user back to the same page if url has "code" parameter in query string
if(isset($_GET['code'])){
header('Location: ./');
}

// Getting user facebook profile info
try {
$profileRequest = $fb->get('/me?fields=name,first_name,last_name,email,link,gen der,locale,picture');
$fbUserProfile = $profileRequest->getGraphNode()->asArray();
} catch(FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
session_destroy();
// Redirect user back to app login page
header("Location: ./");
exit;
} catch(FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}

// Initialize User class
/* ---------------------- PARTE DB ------------------------*/

$user = new User();

// Insert or update user data to the database
$fbUserData = array(
'oauth_provider'=> 'facebook',
'oauth_uid' => $fbUserProfile['id'],
'first_name' => $fbUserProfile['first_name'],
'last_name' => $fbUserProfile['last_name'],
'email' => $fbUserProfile['email'],
'gender' => $fbUserProfile['gender'],
'locale' => $fbUserProfile['locale'],
'picture' => $fbUserProfile['picture']['url'],
'link' => $fbUserProfile['link']
);
$userData = $user->checkUser($fbUserData);

// Put user data into session
$_SESSION['userData'] = $userData;

// Get logout url
$logoutURL = $helper->getLogoutUrl($accessToken, $redirectURL.'logout.php');

// Render facebook profile data
if(!empty($userData)){
$output = "<h1>APP ID ".$appId ."</h1>";
$output .= '<h1>Facebook Profile Details </h1>';
$output .= '<img src="'.$userData['picture'].'">';
$output .= '<br/>Facebook ID : ' . $userData['oauth_uid'];
$output .= '<br/>Name : ' . $userData['first_name'].' '.$userData['last_name'];
$output .= '<br/>Email : ' . $userData['email'];
$output .= '<br/>Gender : ' . $userData['gender'];
$output .= '<br/>Locale : ' . $userData['locale'];
$output .= '<br/>Logged in with : Facebook';
$output .= '<br/><a href="'.$userData['link'].'" target="_blank">Click to Visit Facebook Page</a>';
$output .= '<br/>Logout from <a href="'.$logoutURL.'">Facebook</a>';
}else{
$output = '<h3 style="color:red">Some problem occurred, please try again.</h3>';
}

}else{
// Get login url
$loginURL = $helper->getLoginUrl($redirectURL, $fbPermissions);

// Render facebook login button
$output = '<a href="'.htmlspecialchars($loginURL).'"><img src="images/fblogin-btn.png"></a>';
}
?>
<html>
<head>
<title>Login with Facebook using PHP by CodexWorld</title>
<style type="text/css">
h1{font-family:Arial, Helvetica, sans-serif;color:#999999;}
</style>
</head>
<body>
<!-- Display login button / Facebook profile information -->
<div><?php echo $output; ?></div>
</body>
</html>



---------------- fbConfig.php -----------------

<pre lang="PHP">
error_reporting(E_ALL);
if(!session_id()){
session_start();
}

// Include the autoloader provided in the SDK
require_once __DIR__ . '/facebook-php-sdk/autoload.php';

// Include required libraries
use Facebook\Facebook;
use Facebook\Exceptions\FacebookResponseException;
use Facebook\Exceptions\FacebookSDKException;

/*
* Configuration and setup Facebook SDK
*/


$appId = '22xxxxxxxx'; //Facebook App ID
$appSecret = '50xxxxxx'; //Facebook App Secret
$redirectURL = 'http://xxxxx.altervista.org/fbapp0'; //Callback URL
$fbPermissions = array('email'); //Optional permissions



$fb = new Facebook(array(
'app_id' => $appId,
'app_secret' => $appSecret,
'default_graph_version' => 'v2.2',
));

// Get redirect login helper
$helper = $fb->getRedirectLoginHelper();

// Try to get access token
try {
if(isset($_SESSION['facebook_access_token'])){
$accessToken = $_SESSION['facebook_access_token'];
}else{
$accessToken = $helper->getAccessToken();
}
} catch(FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}



In the facebook app configuration panel:

Valid OAuth redirect URIs

http://xxxx.altervista.org/ e http://xxxx.altervista.org/fbapp0/

Again, these two scripts copied with the sdk facebook folder on another site work fine, Thanks in advance for the answers, a greeting
QuestionPHP Getting Data From Javascript Pin
Valecia_cho23-Oct-17 13:48
Valecia_cho23-Oct-17 13:48 
AnswerRe: PHP Getting Data From Javascript Pin
Richard Deeming24-Oct-17 2:08
mveRichard Deeming24-Oct-17 2:08 
QuestionHow do I Attach acrobat pdf page to email in codeigniter? Pin
Member 1347022217-Oct-17 4:13
Member 1347022217-Oct-17 4:13 
SuggestionRe: TLDR Pin
Richard Deeming17-Oct-17 4:31
mveRichard Deeming17-Oct-17 4:31 
QuestionThinkphp 5.0 query table how the array of how to get rid of a column? And then save it to another table? Pin
micccn13-Oct-17 23:37
micccn13-Oct-17 23:37 
Questionhelp me on my php script Pin
horlartech8-Sep-17 12:03
horlartech8-Sep-17 12:03 
SuggestionRe: help me on my php script Pin
Richard MacCutchan8-Sep-17 19:24
mveRichard MacCutchan8-Sep-17 19:24 
GeneralRe: help me on my php script Pin
horlartech10-Sep-17 2:39
horlartech10-Sep-17 2:39 
GeneralRe: help me on my php script Pin
horlartech10-Sep-17 2:49
horlartech10-Sep-17 2:49 
QuestionRe: help me on my php script Pin
Richard MacCutchan10-Sep-17 4:17
mveRichard MacCutchan10-Sep-17 4:17 
QuestionCall to a member function prepare() on a non-object Pin
Igoussam28-Aug-17 10:56
Igoussam28-Aug-17 10:56 
AnswerRe: Call to a member function prepare() on a non-object Pin
Richard MacCutchan28-Aug-17 21:36
mveRichard MacCutchan28-Aug-17 21:36 
Questionhow to get hard disk Serial Number using php on server side Pin
Lakshmanan Duraisamy26-Jul-17 23:15
Lakshmanan Duraisamy26-Jul-17 23:15 
AnswerRe: how to get hard disk Serial Number using php on server side Pin
Richard MacCutchan26-Jul-17 23:35
mveRichard MacCutchan26-Jul-17 23:35 
AnswerRe: how to get hard disk Serial Number using php on server side Pin
Jochen Arndt27-Jul-17 0:09
professionalJochen Arndt27-Jul-17 0:09 
SuggestionRe: how to get hard disk Serial Number using php on server side Pin
Richard Deeming27-Jul-17 1:31
mveRichard Deeming27-Jul-17 1:31 
QuestionPHP connecting to vb.Net Pin
Member 1296881918-Jul-17 19:48
Member 1296881918-Jul-17 19:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.