Jump to content

Facebook app form that reconnects to user Access_token And Userid post to DB


Grundell

Recommended Posts

Hello,

 

Have a question that i hope some one can help me answer.

 

I have started creating a facebook app that will translate lovepoems.

 

The problem im having is that facebook redirects everything wrong, which makes my life a living hell. So what i thought is it's possible to while submitting the form and the user gets redirected to the facebook allow app page, wait with submitting the form or maybe bring the post id with me and then post the content to the db liked to the post from a different page.

 

simply so i don't have to make the accept form and then go to the actual content?

 

 

So I'm using Wordpress as default CMS system if that helps.

 

This is the code.

 

<?php
/*
Template Name: Febuary Love testing app 
*/
?>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original:  Wayne Nolting (w.nolting@home.com) -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function verify() {
var themessage = "You are required to complete the following fields: ";
if (document.form.title.value=="") {
themessage = themessage + " - Title";
}
if (document.form.description.value=="") {
themessage = themessage + " -  Poem";
}
if (document.form.post_tags.value=="") {
themessage = themessage + " -  Keywords";
}
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {
document.form.submit();
}
else {
alert(themessage);
return false;
   }
}
//  End -->
</script>

<?php
add_filter('fb_php_sdk_load','your_filter');
function your_filter($array)
{
    $array[] = '2.1.2'; //exact version number you need
    return $array;
}

$facebook = new Facebook(array(
	'appId' => '179200268852090',
	'secret' => '3b62bc6b207e4038aa56a28bfc5ed368',
	'cookie' => true,  

));

$session = $facebook->getUser();

if (!empty($session))
	{
		try{
			$user = $facebook->getUser();
			$user = $facebook->api('/me');
		}
		catch (Exception $e){
		}


	if (!empty($user))
	{

	}
	else
		die ("An error occured");
}
else{
	$loginUrl = $facebook->getLoginUrl(array(
	    'canvas' => 1,
	    'fbconnect' => 0,
	    'scope' => 'offline_access, publish_stream'
	));
		echo "<a href='".$loginUrl."'>Click </a> to add the Copypanther Facebook application";
	} 
?>

<?php
$user = $facebook->getUser();
if($user){
    $access_token = $facebook->getAccessToken();

}
?>


<?php
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&  $_POST['action'] == "new_post") {

// Do some minor form validation to make sure there is content
if (isset ($_POST['title'])) {
	$title =  $_POST['title'];
} else {
	echo 'Please enter the Poem name';
}
if (isset ($_POST['description'])) {
	$description = $_POST['description'];
} else {
	echo 'Please enter some notes';
}

$tags = $_POST['post_tags'];
$access_token = $_POST['access_token'];
$user = $_POST['user'];

// ADD THE FORM INPUT TO $new_post ARRAY
$new_post = array(
'post_title'	=>	$title,
'post_content'	=>	$description,
'post_category'	=>	array($_POST['cat']),  // Usable for custom taxonomies too
'tags_input'	=>	array($tags),
'post_status'	=>	'draft',           // Choose: publish, preview, future, draft, etc.
'post_type'	=>	'post',  //'post',page' or use a custom post type if you want to
'access_token' => $access_token,
'user' => $user,
);

//SAVE THE POST
$pid = wp_insert_post($new_post);
add_post_meta($pid, 'access_token', $access_token, true);
add_post_meta($pid, 'user', $user, true);

    //SET OUR TAGS UP PROPERLY
wp_set_post_tags($pid, $_POST['post_tags']);

//REDIRECT TO THE NEW POST ON SAVE
$link = get_permalink( $pid );
wp_redirect('http://www.ngee.se');

} // END THE IF STATEMENT THAT STARTED THE WHOLE FORM

//POST THE POST YO
do_action('wp_insert_post', 'wp_insert_post');

get_header(); ?> 


<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?> 


                    <div class="form-content">
                        <?php the_content(); ?>

					<!-- WINE RATING FORM -->

					<div class="wpcf7">
						<h2>Share some February Love!</h2>
						<p>Although the 14th of February might and should be dedicated to your loved one, we think that friends, bosses and coworkers deserve some affection, too. So between the 1st and 13th of February we will translate a poem or message from you to them <em>for free</em></p>
					<form id="new_post" name="new_post" method="post" action="" class="wpcf7-form" enctype="multipart/form-data">
						<!-- post name -->
						<fieldset name="name">
							<label for="title">Love poem name:</label>
							<input type="text" id="title" value="" tabindex="5" name="title" />
						</fieldset>

						<!-- post Category -->
						<fieldset class="category">
							<label for="cat">Translate to:</label>
							<?php wp_dropdown_categories( 'tab_index=10&taxonomy=category&hide_empty=0' ); ?>
						</fieldset>

						<!-- post Content -->
						<fieldset class="content">
							<label for="description">Love poem:</label>
							<textarea id="description" tabindex="15" name="description" cols="80" rows="10"></textarea>
						</fieldset>

						<!-- post tags -->
						<fieldset class="tags">
							<label for="post_tags">Keywords (comma separated):</label>
							<input type="text" value="" tabindex="35" name="post_tags" id="post_tags" />
						</fieldset>
						<SCRIPT LANGUAGE="JavaScript">
						function testResults (form) {
						var TestVar = form.submit();
						}
						</SCRIPT>
						<fieldset class="submit">
								<input type=button value="Send" value="Send" tabindex="40" id="submit" name="submit" onclick="verify();">
						</fieldset>

						<fieldset class="access_token">
							<label for="access_token"></label>
							<input type="text" value="<?php echo $access_token;?>" id="access_token" name="access_token"/>
						</feildset>

						<fieldset class="user">
							<label for="user"></label>
							<input type="text" value="<?php echo $user;?>" id="user" name="user" />
						</feildset>

						<input type="hidden" name="action" value="new_post" />
						<?php wp_nonce_field( 'new-post' ); ?>
					</form>
					</div> <!-- END WPCF7 -->

                        <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
                        <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="edit-link">', '</span>' ); ?>
                    </div><!-- .entry-content -->
                </div><!-- #post-## --> 

<?php endwhile; // end of the loop. ?> 

<?php get_footer(); ?>

 

Any one have any idea about how i can solve this problem ?

 

Answers most appreciated!

 

Best Regards

GrundeLL

 

 

EDIT ***

 

I'm using facebook PHP SDK

Link to comment
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.