提示用户使用 PHP SDK 发布 feed

发布于 2024-12-08 14:01:17 字数 1274 浏览 1 评论 0原文

抱歉我的英语不好,我会尽力解释我的问题。

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

        $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>

那样全部!

Sorry for my English, I'll try to explain my problem.

With this code I can publish feed on the wall of the users without prompts (I need extended permissions..)

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

But How can I use PHP SDK to prompts the user to publish as can be done with this code (using 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>

Thanks to all!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月野兔 2024-12-15 14:01:17

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

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


参考:https://developers.facebook.com/docs/reference/dialogs/#显示


示例:正在建设中。

<?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();

}    
?>

Seems you will need to cUrl the dialog end point to get the effect you desire.
I would suggest using a button or link and opening a new page which will cUrl the endpoint and redirect back to that page with a close tab or page button.

example endpoint link 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


Refer to: https://developers.facebook.com/docs/reference/dialogs/#display


examples: under construction.

<?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();

}    
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文