duanke6057 2012-08-30 12:10
浏览 47
已采纳

facebook php SDK,publish_stream OAuthException:(#200)

I know this error has been bitten to death over here, and I read every single one to have better understanding of my problem.

But my issue is a bit different, and I wonder if anyone can give me good suggestion where to look.

I'm using wordpress + wordpress social login. This plugin authenticates user and stores name/age/email/fbID/fbProfilePic in the DB.

I've a little feature on my website where users registered through facebook can click and post message to the their wall.

My code looks like this:

<?php
//IF user is registered via facebook, when he clicks INTERESTED message will appear on his/her wall to spread the news

  $user = get_user_meta($current_user->ID,'Facebook',true);

    if ($user && $_GET['commentstab'] == 1 && !$_POST['delmycom']) {



      require ('Facebook/facebook.php');

      //Access details
      $facebook = new Facebook(array(
        'appId'  => 'XXX',
        'secret' => 'XXX'
        //'cookie' => true
      ));


          //try {
              $params = array(
                  'message'       =>  "Hurray! This works :)",
                  'name'          =>  "This is my title",
                  'caption'       =>  "My Caption",
                  'description'   =>  "Some Description...",
                  'link'          =>  "http://stackoverflow.com",
                  'picture'       =>  "http://i.imgur.com/VUBz8.png",
              );
              $post = $facebook->api("/$user/feed","POST",$params);

              echo "Your post was successfully posted to UID: $user";
          //} //try

          //catch (FacebookApiException $e) {
          //    $result = $e->getResult();
          //} //catch


    } //master if
?>

I read in various topics that I need publish_stream permission from user to perform this action. But since I store user info separately in my own DB, how do I get this publish stream permission? Do I need to modify wordpress plugin to store some kind of access token? and utilize this token to post to wall?

  • 写回答

1条回答 默认 最新

  • dongyou8087 2012-08-30 12:26
    关注
    1. you generate loginurl with publish_stream permission
    2. if user is not logged in with permission, you have to make sure he does
    3. redirect user to proper page

    you can do it like this,

    <?php
    include_once("facebook.php"); 
        $facebook = new Facebook(array(
          'appId'  => APP_ID,
          'secret' => APP_SECRET,
          'cookie' => true,
        ));
        $user = $facebook->getUser();
    
    
    
        if ($user) {
          try {
            // Get the user profile data you have permission to view
            $user_profile = $facebook->api('/me');
          } catch (FacebookApiException $e) {
            $user = null;
          }
        } else {
            $loginUrl = $facebook->getLoginUrl(array('scope' =>'publish_stream','redirect_uri'=>'example.com'));
          die('<script> top.location.href="'.$loginUrl.'";</script>');
        }
    
        $params = array(
                      'message'       =>  "Hurray! This works :)",
                      'name'          =>  "This is my title",
                      'caption'       =>  "My Caption",
                      'description'   =>  "Some Description...",
                      'link'          =>  "http://stackoverflow.com",
                      'picture'       =>  "http://i.imgur.com/VUBz8.png",
                  );
        $post = $facebook->api("/$user/feed","POST",$params); 
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示