0

我一直在尝试阅读朋友的新闻提要以检查我的消息是否存在(无论消息是可见、隐藏还是删除),如果消息存在,则不要发布新消息。如果它不存在,则发布消息。下面的代码有很多不必要的代码来追踪问题的来源。我为“publish_stream,read_stream”设置了权限。

我尝试了其他博客中的所有代码,但似乎没有工作我不知道是不是因为我使用的是 PHP SDK 3.0 - 最新版本。我的应用程序是 iframe 应用程序。甚至在 Facebook 应用程序上购买了一本昂贵的书(太贵了),但购买后发现它已经过时了!

如果我使用 /me 或我的用户 ID 但不是我朋友的 ID,则该代码运行良好。

require 'config.php';
require 'facebook.php';


//Create facebook application instance.
$facebook = new Facebook(array(
  'appId'  => $fb_app_id,
  'secret' => $fb_secret
));


$sent = false;
$userData = null;
$PPnotposted = true;
$me = null;
$test_friends =1;

$user = $facebook->getUser();

// Login or logout url will be needed depending on current user state.
if ($user) {
  $logoutUrl = $facebook->getLogoutUrl(array("next"=> "<? echo $fb_app_url ?>" ));
} else {
  $loginUrl = $facebook->getLoginUrl( array( 'scope'=> 'publish_stream, read_stream', 'redirect_uri' => $fb_app_url));
}

$get_someone_else = 100000xxxxxxxxx; // I used a real user id but covered it up here so
                                     my friend's id hidden for this stackexchange help

if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    if ( $get_someone_else ){
    $user_profile = $facebook->api("/".$get_someone_else);
    echo "<br/> ********************user is ".$get_someone_else." ******************<br/>";
    var_dump( $user_profile );  
    echo "<br/> ********************** end of user info ******************<br/>";   
    } else {
    $user_profile = $facebook->api('/me');
    }
  } catch (FacebookApiException $e) {
  }
// print_r( $user_profile );  
$PPaccesstoken = $facebook->getAccessToken(); 
$attachment[access_token]= $PPaccesstoken ;


    //post message to wall if it is sent through form

    if(isset($_POST['PPmessage'])){
        try {
           if( $get_someone_else ){
          $ppmy_news = $facebook->api("/.$get_someone_else./feed?limit=300");     //Get 300 messages to examine
    echo "<br/> *********************** news feed is ".$ppmy_news." ******************<br/>";
    var_dump( $ppmy_news );  
    echo "<br/> ******************** end of user info ********************<br/>";             
           } else {
          $ppmy_news = $facebook->api('/me/feed?limit=300');  //Get 300 messages 
                                                   //to examine. Initially I set it to
                                                   // 10 messages for testing purposes.
          }


//        var_dump( $ppmy_news);        
//          $sent = $facebook->api("/".$user."/feed", 'POST', $attachment );

          $ppmy_view_lp=0;
          if( $test_friends ) {     //Debugging flag to activate or deactivate parts of code
          echo "sent is :<br />";
//        var_dump( $sent ); 
          echo "<br />";
          $friends = $facebook->api('/me/friends');
          echo "friends is :<br />";
//        var_dump( $friends ); 
          echo "<br />";
                  $friendsLists = $facebook->api('/me/friends');
                  $total_friends = 0;
                  foreach ($friendsLists as $friends) {
                    foreach ($friends as $friend) {
                      $id = $friend['id'];
                      $name = $friend['name'];
                  $total_friends++;  //Get total number of friends
                      echo "friend : ".$name." id is: ".$id." Total friends is : ".$total_friends." <br/> ";
                     }
                  } 
          }
        } catch (FacebookApiException $e) {
        echo "<br/> !!!!!!!!!!!! Error Dump Line 85 !!!!!!!!!!!!! <br/>";
        var_dump( $e );
        echo "<br/> !!!!!!!!!!!! End of Error Dump !!!!!!!!!!!!! <br/>";        
            //do something about it
        }
    }

}

但我发现我被拒绝许可,并且捕获转储是:

!!!!!!!!!!!!错误转储行 85 !!!!!!!!!!!!!!! object(FacebookApiException)#2 (7) { ["result:protected"]=> array(1) { ["error"]=> array(3) { ["message"]=> string(72) "(# 803)您请求的某些别名不存在:.100000xxxxxxxxx。” ["type"]=> string(14) "OAuthException" ["code"]=> int(803) } } ["message:protected"]=> string(72) "(#803) 你的一些别名请求的不存在:.100000xxxxxxxxx。” ["string:private"]=> string(0) "" ["code:protected"]=> int(0) ["file:protected"]=> string(48) "/home/www/drpetersnews.com /vmt/base_facebook.php" ["line:protected"]=> int(1106) ["trace:private"]=> array(4) { [0]=> array(6) { ["file"]= > string(48) "/home/www/drpetersnews.com/vmt/base_facebook.php" ["line"]=> int(810) ["function"]=> string(17) "throwAPIException" ["class"] => string(12) "BaseFacebook" ["type"]=> string(2) "->" ["args"]=> array(1) { [0]=> array(1) { ["error" ]=> array(3) { ["message"]=> string(72) "(#803) 您请求的某些别名不存在:.100000xxxxxxxxx。" ["type"]=> string(14) "OAuthException" ["code"]=> int(803) } } } } [1]=> array(4) { ["function"]=> string(6) "_graph" ["class"]=> string(12) "BaseFacebook" ["type"]=> string(2) "->" ["args"]=> array(1) { [0]=> string (32) "/. 字符串(6)“_graph”}[1]=>数组(1){[0]=>字符串(32)“/.100000xxxxxxxxx./feed?limit=10”}}}[3]=>数组(6 ) { ["file"]=> string(40) "/home/www/drpetersnews.com/vmt/index.php" ["line"]=> int(54) ["function"]=> string(3 ) "api" ["class"]=> string(12) "BaseFacebook" ["type"]=> string(2) "->" ["args"]=> array(1) { [0]=> string(32) "/.100000xxxxxxxxx./feed?limit=10" } } } } !!!!!!!!!!!!!!! 错误转储结束!!!!!!!!!!!!!字符串(6)“_graph”}[1]=>数组(1){[0]=>字符串(32)“/.100000xxxxxxxxx./feed?limit=10”}}}[3]=>数组(6 ) { ["file"]=> string(40) "/home/www/drpetersnews.com/vmt/index.php" ["line"]=> int(54) ["function"]=> string(3 ) "api" ["class"]=> string(12) "BaseFacebook" ["type"]=> string(2) "->" ["args"]=> array(1) { [0]=> string(32) "/.100000xxxxxxxxx./feed?limit=10" } } } } !!!!!!!!!!!!!!! 错误转储结束!!!!!!!!!!!!!

请帮帮我,让我知道我是否错误地设置了权限以及如何正确设置。

4

1 回答 1

0

代码是正确的,但问题可能出在 Facebook 的隐私设置上。如果您看不到用户墙上的帖子,则表示用户设置了隐私设置,阻止您查看帖子。

使用 Graph API Explorer 工具 (https://developers.facebook.com/tools/explorer/) 并查看是否可以使用它查看用户的提要。检查多个朋友 ID 以查看其中是否有任何返回数据。

于 2012-05-23T11:12:14.913 回答