dongxun6690 2011-08-26 23:41
浏览 105
已采纳

使用Facebook PHP SDK发布到用户的Facebook Wall

I'm integrating my web-based game to a Facebook Game . Facebook login, getting user id, getting user profile picture is OK . But i need to post somethings to wall (For example, John Doe earned 50 point!) .

I have offline_access and publish_Stream permissions for my Facebook App.

Now i want to publish some links automatically. I'm using Facebook PHP SDK with Yii.

I can get Facebook User ID etc... But i don't know how can i post somethings to user's wall, automatically (for example when user is offline).

I'm looking Graph API Post document's Publishing title. But i need access_token parameter for use this. And i'm not sure where is this access_token .

  • 写回答

3条回答 默认 最新

  • dongleiwei2182 2011-08-27 02:42
    关注

    PHP-SDK 3.1.1

    To generate app and user tokens. $app_access_token & $access_token

    *The user access_token if you have offline access will never expire, unless user deAuthorizes your app. You would need to use for posting to a users wall when they are offline or not interacting with your application.*


    <?php
    require './src/facebook.php';
    $facebook = new Facebook(array(
      'appId'  => '135669679827333',
      'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    ));
     $user = $facebook->getUser();
     if ($user) {
       try {
         // Proceed knowing you have a logged in user who's authenticated.
         $user_profile = $facebook->api('/me');
       } catch (FacebookApiException $e) {
         error_log($e);
         $user = null;
       }
     }
     if ($user) {
       $logoutUrl = $facebook->getLogoutUrl();
     } else {
       $loginUrl = $facebook->getLoginUrl();
     }
    // Create Application Access Token
    $app_access = "https://graph.facebook.com/oauth/access_token?client_id=135669679827333&client_secret=xxxxxxxxxxxxxxxxxxxxxxxx&grant_type=client_credentials";
    $app_access_token = file_get_contents($app_access);
    // If we have a user who is logged in, create access_token with session.
    if ($user) {
    $access_token = $_SESSION['fb_135669679827333_access_token'];
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化