php - how can i post on a wall using onclick attribute? -
i have tried few different ways data post when user clicks it, no avail.
hopefully can help:
<link href="facebook.css" rel="stylesheet" type="text/css"> <div class="fbbody"> <?php require './facebook.php'; $facebook = new facebook(array( 'appid' => ' *******', 'secret' => '******', 'cookie' => true, )); $uid = $facebook->getuser(); $status = $_post['status']; if($status == "") $msg = "please enter status."; else { $msg = "thanks."; } ?> <script> alert('<? echo $msg; ?>'); </script> <div align="center"> <form method="get" action="translate.php"> <textarea name="status2" cols="50" rows="5"/> <?php echo str_ireplace(array ('old','awkward','all','again','behind','along','alright','hello','among','children','yes','child','kids','food','barnard castle','beer','book','blow','beautiful','bird','burst','brown','burn','boots'), array ('auld', 'aakwad', 'aall','agyen','ahint','alang','alreet','alreet','amang','bairns','aye','bairn','bairns','bait','barney','beor','beuk','blaa','bonny','bord','borst','broon','bourn','byeuts'),$status); ?> </textarea><br> <?php $args = array( 'message' => $_get['status2'], 'link' => 'http://apps.facebook.com/geordie-status/', 'caption' => 'translate english geordie' ); $post_id = $facebook->api("/$uid/feed", "post", $args); ?> <input type="submit" value="post wall"/> </form> </div> </div>
the above code translate.php.
how use 'onclick' attribute run below code when clicked, , when button clicked, not before.
<?php $args = array( 'message' => $_get['status2'], 'link' => 'http://apps.facebook.com/geordie-status/', 'caption' => 'translate english geordie' ); $post_id = $facebook->api("/$uid/feed", "post", $args); ?>
to post status message have ask user permissions see: https://developers.facebook.com/docs/reference/login/extended-permissions/ need publish_actions here.
cause want post on on click event have ask permission before show form.
you can use jquery handle on click event (on submit in code below). jquery used send message second page (ajax request). second page (facebookpost.php) post message on wall.
facebook.php:
<? error_reporting(e_all); ini_set('display_errors','on'); require 'facebook-php-sdk-master/src/facebook.php'; $facebook = new facebook(array( 'appid' => '***************', 'secret' => '*******************************', )); $applicationurl = 'http://testdrive.nl/facebook.php'; // user id $user = $facebook->getuser(); if(empty($user)) { $params = array( 'scope' => 'publish_actions', 'redirect_uri' => $applicationurl ); $loginurl = $facebook->getloginurl($params); header('location: ' . $loginurl ."\r\n"); exit; } ?> <!doctype html> <html> <head> <title>facebook testpage</title> </head> <body> <div class="container"> <div id="result"></div> <form id="poster"> <textarea id="status2"></textarea> <input type="submit" value="post wall"/> </form> </div> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script> $('#poster').submit(function() { $.get("facebookpost.php", { status2: $('#status2').val() }, function(data) { $('#result').html(data); }); return false; }); </script> </body> </html>
facebookpost.php:
<? error_reporting(e_all); ini_set('display_errors','on'); require 'facebook-php-sdk-master/src/facebook.php'; $facebook = new facebook(array( 'appid' => '***************', 'secret' => '*******************************', )); //$applicationurl = 'http://testdrive.nl/facebook.php'; // user id $user = $facebook->getuser(); if(empty($user)) { echo 'invalid user'; } $args = array( 'message' => $_get['status2'], 'link' => 'http://apps.facebook.com/geordie-status/', 'caption' => 'translate english geordie' ); $facebook->api("/$user/feed", "post", $args); echo 'posted wall';
Comments
Post a Comment