需要帮助在用户墙上发布 [英] need help on posting on user wall

查看:81
本文介绍了需要帮助在用户墙上发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要帮助下面是我的应用程序的index.php的代码,我想在用户使用OFFLINE_ACCESS和publish_stram授权我的应用程序之后发布在用户墙上

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

<?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. 下载 Facebook PHP-SDK < a>

  2. 不需要 offline_access 权限

  3. 熟悉PHP-SDK并使用示例页面中的代码作为索引,某些内容像:

  1. Download the Facebook PHP-SDK
  2. No need for the offline_access permission
  3. Get familiar with the PHP-SDK and use the code in the example page as your index, something like:

<?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>");
}
?>


  • 欢迎来到Stackoverflow!

  • 这篇关于需要帮助在用户墙上发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆