onclick 속성을 사용하여 어떻게 벽에 게시할 수 있습니까? (how can i post on a wall using onclick attribute?)


문제 설명

onclick 속성을 사용하여 어떻게 벽에 게시할 수 있습니까? (how can i post on a wall using onclick attribute?)

i have tried a few different ways to get my data to post only when the user clicks it, but to no avail. 

Hopefully someone 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 a 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 from English to Geordie'
);
$post_id = $facebook‑>api("/$uid/feed", "post", $args);

?>

<input type="submit" value="post to wall"/>

</form>

</div>


</div>

the above code is my translate.php.

how could i use the 'onclick' attribute to run the below code when it is clicked, and only when the button is clicked, not before.

<?php


$args = array(
'message'   => $_GET['status2'],
'link'      => 'http://apps.facebook.com/geordie‑status/',
'caption'   => 'Translate from English to Geordie'
);
$post_id = $facebook‑>api("/$uid/feed", "post", $args);

?>

참조 솔루션

방법 1:

To post a status message you have to ask the user for permissions see: https://developers.facebook.com/docs/reference/login/extended‑permissions/ you will need publish_actions here.

Cause you want to post on the on click event you will have ask the permission before show the form.

You can use jquery to handle your on click event (on submit in the code below). jquery is used to send the message to an second page (ajax request). The second page (facebookpost.php) will post the message on the 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';

// Get 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 to 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';

// Get 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 from English to Geordie'
);
$facebook‑>api("/$user/feed", "post", $args);
echo 'posted to your wall';

(by Cain NealBass Jobsen)

참조 문서

  1. how can i post on a wall using onclick attribute? (CC BY‑SA 3.0/4.0)

#facebook-php-sdk #PHP #facebook #html #facebook-apps






관련 질문

앱 사용자의 담벼락에 자신으로 게시하려면 액세스 토큰이 필요합니까? (Do you need an access token to post on app user's wall as themself?)

onclick 속성을 사용하여 어떻게 벽에 게시할 수 있습니까? (how can i post on a wall using onclick attribute?)

사용자의 담벼락에 게시하고 권한을 요청하는 다른 방법이 있습니까? (Are there different ways to post to user's wall and ask for permissions?)

모바일 장치에서 Facebook PHP SDK에 문제가 있음 (Having trouble with Facebook PHP SDK on mobile devices)

하나의 앱에서 각 페이지에 대해 다른 facebook 보안 페이지 탭 URL을 추가하는 방법 (How to add diffrent facebook Secure Page Tab URL for each page in one app)

모바일 클라이언트에서 서버 및 프로세스로 facebook 액세스 토큰 전달 (Pass facebook access token from mobile client to server and process)

페이지 팔로워 뉴스 피드에 Facebook 팬 페이지 콘텐츠가 표시되지 않음 (Facebook Fan page content not showing in page followers news feed)

이미지 없이 FB 공유 대화 상자 만들기 (Create FB share dialog without image)

Facebook 오류 #100: 사진 URL이 제공된 경우 링크를 제공해야 합니다. (Facebook Error #100 : A link must be provided if a picture URL is given)

맞춤 이벤트에서 웹사이트 맞춤 타겟을 만들려면 어떻게 해야 합니까? (How do I create a website Custom Audience from a custom event?)

수명이 긴 토큰을 얻는 동안 신뢰할 수 없는 결과 (Unreliable results while obtaining long-lived token)

갑자기 주석 플러그인 코드가 주석 상자를 표시하지 않습니다 (Suddenly Comments Plugin code is not showing commenting box)







코멘트