douzhan5262 2012-08-27 12:32
浏览 41
已采纳

PHP将自定义应用操作发布到时间轴

I want my site to have better fb integration than it currently does. As of right now, I use the following code to post a message/link to a given user's timeline.

$attachment = array('message' => 'Predicted the '.ucwords($winning_team_short).' to beat the '.ucwords($losing_team_short).' on '.ordSuffix($new_date_format).'',
            'caption' => 'Sportannica - Online Sports Encyclopedia',
            'name' => 'How will your predictions pan out?',
            'link' => 'http://www.sportannica.com/games/'.$league.'/'.$game.'/predictions',
            'description' => ''.ucwords($winning_team_short).' ('.$winning_score.')  '.ucwords($losing_team_short).' ('.$losing_score.')',
            'picture' => 'http://www.sportannica.com'.$path.''.$winning_team.'.png'
        );

        $facebook->api('/me/feed/', 'post', $attachment);

I want a better method though... one that posts a message to a user's timeline much like the way an app like spotify does.

When I go to the open graph dashboard, I have defined several custom action and object. One action is to "predict". I want to make it so that the message reads "".$fb_user_name." has predicted the ".$winning_team." to beat the ".$losing_team." on ".$game_date."";

I'm relatively new to the fb api, so I'm a bit lost when it comes to this material. I do know that spotify's method uses custom actions so I know that I'm on the right path. Could anyone post some sample php code for their method of posting a message that utilizes custom actions and objects to a user's timeline?

Thanks,

Lance

  • 写回答

1条回答 默认 最新

  • doukong6031 2012-08-27 12:33
    关注

    Example:

    Using php sdk 3.1.1 / in a batch query, other queries removed.

       $queries = array(
            array('method' => 'POST', 'relative_url' => '/me/anotherfeed:view?feed=http://anotherfeed.com/?fbid='.$thepage[id].'')
            // any other api calls needed, this is a batch request for performance.
       );
        try {
     $postResponseA = $facebook->api('?batch='.json_encode($queries), 'POST');
        } catch (FacebookApiException $e) {
      //echo 'AF error: '.$e.'';
      }
      $actions=json_decode($postResponseA[0][body], true);
    

    The post above is broken in to 4 part

    Namespace anotherfeed:

    Action view?

    Object feed

    URL http://anotherfeed.com/?fbid='.$thepage[id].'

    This produces "User Viewed Whatever Feed on Another Feed"


    The action depends on OG Meta tags in the head of the page to fill the action post.

    Example Tags:

    <meta property="og:title" content="SecurityNewsDaily" />    
    <meta property="og:description" content="SecurityNewsDaily on Another Feed, Feeding on the best of Facebook, one page at a time." />
    <meta property="og:type" content="anotherfeed:feed" />
    <meta property="og:image" content="https://graph.facebook.com/146893188679657/picture?type=large" />
    <meta property="og:site_name" content="AnotherFeed" />
    <meta property="fb:app_id" content="135669679827333" />
    <meta property="fb:admins" content="732484576" />
    <meta property="og:url" content="http://anotherfeed.com/index.php?fbid=146893188679657" />
    <meta property="og:restrictions:age" content="13+"/>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器