首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >阅读用户Wall Post和其他在wall上发帖的人

阅读用户Wall Post和其他在wall上发帖的人
EN

Stack Overflow用户
提问于 2011-12-15 02:46:34
回答 1查看 490关注 0票数 0

我是facebook图形API的新手,但我知道基础知识。现在我需要你的帮助,所有关于如何阅读用户墙上的帖子和其他人谁张贴在任何用户的墙上,与read_stream。但我不知道该怎么叫它。我尝试了一些方法,但我只能读到名字和基本信息。我需要阅读对象的帮助。请帮帮我!

代码语言:javascript
复制
<?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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-12-15 03:47:29

首先,您必须获得用户的权限

代码语言:javascript
复制
    $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>

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

代码语言:javascript
复制
    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>";
                    }
                }
            }
        }
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8509990

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档