提示用户使用PHP SDK发布Feed

时间:2011-10-07 15:30:59

标签: facebook-graph-api dialog facebook-php-sdk

对不起我的英语,我会尝试解释我的问题。

使用此代码,我可以在没有提示的情况下在用户的墙上发布Feed(我需要扩展权限..)

        $ret_obj = $facebook->api('/me/feed', 'POST',
                                array(
                                  'link' => 'www.example.com',
                                  'message' => 'Posting with the PHP SDK!'
                             ));

但是如何使用PHP SDK来提示用户发布,就像使用此代码一样(使用Javascript SDK)

    <script src='http://connect.facebook.net/en_US/all.js'></script>
<p><a onclick='postToFeed(); return false;'>Post to Feed</a></p>
<p id='msg'></p>

<script> 
  FB.init({appId: "YOUR_APP_ID", status: true, cookie: true});

  function postToFeed() {

    // calling the API ...
    var obj = {
      method: 'feed',
      link: 'https://developers.facebook.com/docs/reference/dialogs/',
      picture: 'http://fbrell.com/f8.jpg',
      name: 'Facebook Dialogs',
      caption: 'Reference Documentation',
      description: 'Using Dialogs to interact with users.'
    };

    function callback(response) {
      document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
    }

    FB.ui(obj, callback);
  }

</script>

感谢所有人!

1 个答案:

答案 0 :(得分:0)

似乎你需要cUrl对话终点来获得你想要的效果 我建议使用一个按钮或链接并打开一个新页面,该页面将关闭端点并使用关闭选项卡或页面按钮重定向回该页面。

示例端点链接https://www.facebook.com/dialog/feed?app_id=135669679827333&link=https://developers.facebook.com/docs/reference/dialogs/&picture=http://fbrell.com/f8.jpg&name=Facebook%20Dialogs&caption=Reference%20Documentation&description=Using%20Dialogs%20to%20interact%20with%20users.&redirect_uri=http://anotherfeed.com/?pid=facebook


请参阅:https://developers.facebook.com/docs/reference/dialogs/#display


示例:正在建设中。

<?php
require 'facebook.php';
// Create our application instance
// (replace this with your appId and secret).
$app_id = "APP_ID";
$secret = "APP_SECRET";
$app_url = "APP_URL";

$facebook = new Facebook(array(
  'appId'  => $app_id,
  'secret' => $secret,
  'cookie' => true,
));

// Get User ID
$user = $facebook->getUser();
if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
    $access_token = $facebook->getAccessToken();

}    
?>