【问题标题】:Read User Wall Post and others who posted on wall阅读用户墙帖和其他在墙上发帖的人
【发布时间】:2011-12-14 18:46:34
【问题描述】:

我是 facebook graph API 的新手,但我知道基础知识。现在我需要你们所有人的帮助,了解如何使用read_stream 阅读用户墙帖子和其他在任何用户的墙上发布的帖子。但我不知道怎么称呼它。我尝试了一些方法,但我只能读取名称和基本信息。我在阅读物品方面需要帮助。请帮帮我!!!

<?php
define('FACEBOOK_APP_ID', 'xxxxxx');
define('FACEBOOK_SECRET', 'xxxxxx');
function get_facebook_cookie($app_id, $application_secret) {
$args = array();
parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
ksort($args);
$payload = '';
foreach ($args as $key => $value) {
if ($key != 'sig') {
  $payload .= $key . '=' . $value;
 }
 }
  if (md5($payload . $application_secret) != $args['sig']) {
   return null;
  }
 return $args;
  }
  $cookie = get_facebook_cookie(FACEBOOK_APP_ID, FACEBOOK_SECRET);
   ?>
   <!DOCTYPE html>
   <html xmlns="http://www.w3.org/1999/xhtml"
         xmlns:fb="http://www.facebook.com/2008/fbml">
   <body>
   <?php
   echo 'Your Facebook ID: '.$cookie;
    if ($cookie) {
   //cookie is set, user is logged in
   $user = json_decode(file_get_contents('http://graph.facebook.com/'.$cookie['uid']));
   //Display the facebook user ID, name, gender and Facebook URL in the web browser
   echo '<br />';
   echo 'Your Facebook ID: '.$user->{'id'};
   echo '<br />';
   echo 'Your name: '.$user->{'name'};
   echo '<br />';
   echo 'Your gender: '.$user->{'gender'};
   echo '<br />';
   echo 'Your Facebook URL: '.$user->{'link'};
   echo '<br />';
   echo '<img src="http://graph.facebook.com/'.$user->{'id.'/picture"                      alt="'.$user->       {'name'}.'"/>';
   echo '<br />';
   echo '<fb:login-button autologoutlink="true"></fb:login-button>';
   }
   else
   {
   //user is not logged in, display the Facebook login button
          echo '<h2>Facebook Application Test page</h2>';
   echo '<br />';
   echo' message somethng';
   </body>
   </html>

【问题讨论】:

    标签: facebook facebook-graph-api


    【解决方案1】:

    首先,您必须获得用户的许可

        $url = "https://graph.facebook.com/oauth/authorize?"
        ."client_id=".$app_id."&"
        ."redirect_uri=http://apps.facebook.com/".$app_name."/&scope=read_stream";
    
        <script language="javascript">window.open('<?php echo $url ?>', '_parent', '');</script>
    

    然后你就可以得到用户的墙了。这里有一个例子。

        if(isset($_GET["code"])){
            if(isset($_REQUEST['state']) == isset($_SESSION['state'])) {
                $token_url = "https://graph.facebook.com/oauth/access_token?"
                             . "client_id=" . $app_id . "&redirect_uri=" . "http://apps.facebook.com/".$app_name."/"
                             . "&client_secret=" . $app_secret . "&code=" . $_GET["code"];
                $response = @file_get_contents($token_url);
                $params = null;
                parse_str($response, $params);
                $graph_url = "https://graph.facebook.com/".$user_id."/feed/?access_token=".$params['access_token'];
                $user = json_decode(file_get_contents($graph_url));
                foreach($user as $feeds)
                {
                    foreach($feeds as $feed)
                    {
                        if(isset($feed->link))
                        {
                            echo $feed->link."<br>";
                        }
                    }
                }
            }
        }
    

    【讨论】:

    • 感谢您的帮助,但现在弹出这两个错误:警告:file_get_contents(graph.facebook.com//feed/?access_token=) [function.file-get-contents]:打开流失败:HTTP 请求失败!第 34 行 /data/multiserv/users/491819/projects/1209278/www/fb/abc.php 中的 HTTP/1.0 500 内部服务器错误警告:/data/multiserv/users/491819/ 中为 foreach() 提供的参数无效projects/1209278/www/fb/abc.php 第 35 行
    • 你的 php 版本是多少?您需要 PHP5.2+ 才能使用 Facebook SDK
    • 并在您的 php.ini 文件中更改 allow_url_fopen = on
    • 感谢您的快速回复......并且我正在使用子域免费托管网站。我无法编辑 php.ini 。先生,还有其他方法吗?
    • 这个需要 PHP SDK,我们不能绕过先生?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-02
    • 1970-01-01
    • 1970-01-01
    • 2012-12-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多