Jump to content

Recommended Posts

Hi

 

I am trying to create some code that will post content to somebody's facebook wall once they login, get their login email address, email it across to me, then redirect the user back to my main website.

 

I have the code to paste to the wall:

 

<?
 
$app_id = "115920985216230";
 
$your_website_link="http://www.mywebsite.com";
 
 
$title="Do you HATE your weight?!!!";
 
$description="The fat loss factor is the new way to lose weight, share on your wall and get a free sample now ";
 
 
$message="GET A FREE SAMPLE NOW";
 
$feed_url = "http://www.facebook.com/dialog/feed?app_id=". $app_id . "&link=".urlencode($your_website_link)."&name=".$title."&picture=".urlencode($picture)."&description=".$description."&redirect_uri=" . urlencode($redirect_user)."&message=".$message;
 
header('Location: '.$feed_url);
 
 if (empty($_REQUEST["post_id"])) {
 
            echo("<script> top.location.href='" . $feed_url . "'</script>");
 
         } else {
 
           echo ("Feed Post Id: " . $_REQUEST["post_id"]);
 
         }
 
?>
 
 
My problem is how do I grab the email address of the user? I tried the following code but it didn't work:
 
 
<?php
// Begin loading the necessary files for the Facebook SDK.
require ( 'autoload.php' );
 
// Load the required PHP classes from the Facebook SDK.
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
 
// Start the session
session_start();
 
// Initialize the Facebook app using the application ID and secret.
FacebookSession::setDefaultApplication( '115920985216230','d4dda3997902353d23958d1c7dfeb670' );
 
// Define Facebook's login helper and redirect back to our page.
$helper = new FacebookRedirectLoginHelper( 'http://www.mysite.com/sample.php' );
 
// Check to ensure our session was started correctly and the access token exists.
if ( isset( $_SESSION ) && isset( $_SESSION['fb_token'] ) ) {
// Using the access token, create a new session.
$session = new FacebookSession( $_SESSION['fb_token'] );
 
// Determine if the defined session is indeed valid.
if ( !$session->validate() ) {
$session = null;
}
 
}
// Check if an active session exists.
if ( !isset( $session ) || $session === null ) {
// If no session exists, let's try to create one.
$session = $helper->getSessionFromRedirect();
}
 
// Make sure we have a session started.
if ( isset( $session ) ) {
// Save the session
$_SESSION['fb_token'] = $session->getToken();
 
 
 
// Create a new Facebook session using our token.
$session = new FacebookSession( $session->getToken() );
 
echo 'Connected to Facebook!';
 
$user = (new FacebookRequest(
      $session, 'GET', '/me?fields=id,name'
    ))->execute()->getGraphObject(GraphUser::className());
 
 
$to      = 'joeblogs@hotmail.co.uk';
$subject = 'User data';
$message = $user;
$headers = 'From: joeblogs@gmail.com' . "\r\n" .
    'Reply-To: brittosd@gmail.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
 
mail($to, $subject, $message, $headers);
 

?>

 

So basically I need some code that uses the new facebook SDK for php that does both, i.e. shares content on the user's wall, emails me the user's email address then redirects them to a page on my website.

 

Thanks

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/295094-facebook-api-problem/
Share on other sites

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.