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 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错