Jump to content

Facebook Login


shiniie

Recommended Posts

Hi!
 
Im trying to make a Facebook login for my website and always get errors. I got the files from GitHub and used the example.php and the files from the src.
 
example.php
 
<?php
/**
 * Copyright 2011 Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may obtain
 * a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
 
require 'facebook.php';
 
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => 'the id',
  'secret' => 'secret',
  'cookie' => true
));
 
 
 
 
// Get User ID
$user = $facebook->getUser();
 
// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.
 
if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}
 
// Login or logout url will be needed depending on current user state.
if ($user) {
  $logoutUrl = $facebook->getLogoutUrl(array(
'next' => 'http://unity.mppsaalk.se', // URL to which to redirect the user after logging out
));;
} else {
  $loginUrl = $facebook->getLoginUrl(array('scope'=> 'publish_stream',  'redirect_uri' => 'http://unity.mppsaalk.se', 
) );
}
 
// This call will always work since we are fetching public data.
$naitik = $facebook->api('/naitik');
 
?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
  <head>
    <title>php-sdk</title>
    <style>
      body {
        font-family: 'Lucida Grande', Verdana, Arial, sans-serif;
      }
      h1 a {
        text-decoration: none;
        color: #3b5998;
      }
      h1 a:hover {
        text-decoration: underline;
      }
    </style>
  </head>
  <body>
    <h1>php-sdk</h1>
 
    <?php if ($user): ?>
      <a href="<?php echo $logoutUrl; ?>">Logout</a>
    <?php else: ?>
      <div>
        Login using OAuth 2.0 handled by the PHP SDK:
        <a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
      </div>
    <?php endif ?>
 
    <h3>PHP Session</h3>
    <pre><?php print_r($_SESSION); ?></pre>
 
    <?php if ($user): ?>
      <h3>You</h3>
      <img src="https://graph.facebook.com/<?php echo $user; ?>/picture">
 
      <h3>Your User Object (/me)</h3>
      <pre><?php print_r($user_profile); ?></pre>
    <?php else: ?>
      <strong><em>You are not Connected.</em></strong>
    <?php endif ?>
 
    <h3>Public profile of Naitik</h3>
    <img src="https://graph.facebook.com/naitik/picture">
    <?php echo $naitik['name']; ?>
  </body>
</html>
 
and i get this message
 

 

Warning: session_start() [function.session-start]: open(/storage/content/70/173870/unity.mppsaalk.se/sessions/sess_bfk38f6sm7l6o2j6380ai1fvp1, O_RDWR) failed: No such file or directory (2) in /storage/content/70/173870/unity.mppsaalk.se/public_html/examples/facebook.php on line 49
php-sdk
 
Login using OAuth 2.0 handled by the PHP SDK: Login with Facebook
PHP Session
 
Array
(
    [fb_567618623258914_state] => d9bad0470cfe40c4939d70d686e8d420
)
You are not Connected.
Public profile of Naitik
 
 Naitik Shah 
Warning: Unknown: open(/storage/content/70/173870/unity.mppsaalk.se/sessions/sess_bfk38f6sm7l6o2j6380ai1fvp1, O_RDWR) failed: No such file or directory (2) in Unknown on line 0
 
Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/storage/content/70/173870/unity.mppsaalk.se/sessions) in Unknown on line 0
 
 
 
and when i click on "login with Facebook ", i get this from Facebook:
 

 

Error
An error occurred. Please try again later.
 
API Error Code: 191
API Error Description: The specified URL is not owned by the application
Error Message: Invalid redirect_uri: Given URL is not allowed by the Application configuration.
Edited by shiniie
Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.