简体   繁体   English

在用户墙上发布时需要帮助

[英]need help on posting on user wall

need help below is the code of index.php of my application and i want to Post on user wall after the user authorize my application with OFFLINE_ACCESS AND publish_stram 下面需要帮助的是我的应用程序的index.php代码,我想在用户使用OFFLINE_ACCESS和publish_stram授权我的应用程序后在用户墙上发布

<?php 

 $app_id = "XXXXXXXXXX";

 $app_secret = "XXXXXXX";

 $canvas_page = "http://apps.facebook.com/esccounsel/";

 $auth_url = "http://www.facebook.com/dialog/oauth?client_id=" 
        . $app_id . "&redirect_uri=" . urlencode($canvas_page) . ("&scope=read_stream publish_stream offline_access");

 $signed_request = $_REQUEST["signed_request"];

 list($encoded_sig, $payload) = explode('.', $signed_request, 2); 

 $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);

 if (empty($data["user_id"])) {
        echo("<script> top.location.href='" . $auth_url . "'</script>");
 } else {
        echo ("Welcome User: " . $data["user_id"]);
 } 

?>

I want to post directly on user wall please answer 我想直接张贴在用户墙上,请回答

  1. Download the Facebook PHP-SDK 下载Facebook PHP-SDK
  2. No need for the offline_access permission 无需offline_access权限
  3. Get familiar with the PHP-SDK and use the code in the example page as your index, something like: 熟悉PHP-SDK,并使用示例页面中的代码作为索引,例如:

     <?php require '../src/facebook.php'; $facebook = new Facebook(array( 'appId' => 'XXXXXXX', 'secret' => 'XXXXXXXX', 'cookie' => true, )); $session = $facebook->getSession(); $loginUrl = $facebook->getLoginUrl(array( "req_perms" => "publish_stream" )); $me = null; if ($session) { try { $uid = $facebook->getUser(); $me = $facebook->api('/me'); echo "Welcome User: " . $me['name'] . "<br />"; $post_id = $facebook->api("/$uid/feed", "post", array("message"=>"Hello World!")); if(isset($post_id)) echo "A new post to your wall has been posted with id: $post_id"; } catch (FacebookApiException $e) { error_log($e); } } else { echo("<script> top.location.href='" . $loginUrl . "'</script>"); } ?> 
  4. Welcome to Stackoverflow! 欢迎来到Stackoverflow!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM