【问题标题】:Post automatically on the wall of user (facebook App)自动发布在用户的墙上(facebook App)
【发布时间】:2013-06-04 16:30:18
【问题描述】:

我希望我的应用代表用户在墙上发布(例如用于广告)。我考虑创建一个 php 脚本,我将每周在我的服务器上执行一个 cron 作业。 我的数据库中有用户标识。 现在我希望脚本获得一个用户 ID,然后在用户的墙上发布。 (当然,如果用户仍然安装了应用程序并授予了发布流权限)

是否可以创建一个触发此功能的脚本?
$post = $facebook->api("/$user1/feed","POST",$params);或
$post = $facebook->api("/$user2/feed","POST",$params);等等...?

感谢建议

<?php

require 'src/facebook.php';
$app_id = 'yourappid';
$app_secret = 'yourappsecret';
$app_namespace = 'appname';
$app_url = 'https://apps.facebook.com/' . $app_namespace . '/';
$scope = 'email,publish_actions';


// Init the Facebook SDK
$facebook = new Facebook(array(
 'appId'  => $app_id,
 'secret' => $app_secret,
));



// Get the current user
$user = $facebook->getUser();

// If the user has not installed the app, redirect them to the Auth Dialog
if (!$user) {
  $loginUrl = $facebook->getLoginUrl(array(
   'scope' => $scope,
   'redirect_uri' => $app_url,
 ));

  print('<script> top.location.href=\'' . $loginUrl . '\'</script>');

   }


    else {

       try {
        $params = array(
            'message'       =>  "your message",
            'name'          =>  "hello world",
            'description'   =>  "hello world",
            'link'          =>  "hello world",
            'picture'       =>  "hello world",
        );

        $post = $facebook->api("/$user/feed","POST",$params);

        echo "";

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

  }

 ?>

【问题讨论】:

  • 除了您要求社区为您编程之外,您对上面的代码还有什么问题?
  • 是否可以创建一个脚本来触发这个? $post = $facebook->api("/$user1/feed","POST",$params);或 $post = $facebook->api("/$user2/feed","POST",$params);等等...?

标签: php facebook permissions facebook-wall


【解决方案1】:

为了解决您的问题,我将与您分享我的代码。 这对我有用。

您只需要编写一些循环来从数据库中选择所有用户 id。

    <?php 

     //// publish as status 

     //// publish post to users 


         require_once("facebook.php");


       $app_id = "xxxxxxxxxxx";
       $app_secret = "xxxxxxxxxxxxxx";
       $my_url = "http://t.xxxxx.net/facebook/publish.php/"; // refer number 

    ///
       $config = array();
      $config['appId'] = 'xxxxxxxx';
      $config['secret'] = 'xxxxxxxxxxxx';
      $config['fileUpload'] = false; // optional

        $facebook = new Facebook($config);
       ///

    ////

      function getAccessToken() {
        if ($this->accessToken !== null) {
          return $this->accessToken;
        }

        $this->setAccessToken($this->getApplicationAccessToken());
        $user_access_token = $this->getUserAccessToken();
        if ($user_access_token) {
          $this->setAccessToken($user_access_token);
        }

        return $this->accessToken;
      }

       function getApplicationAccessToken() {
        return $this->appId.'|'.$this->appSecret;
    }


    /////////////////////////////// Update status Function 
    //xxxxxxxx
    $session = $facebook->getUser();



    // New SDK
    $facebook->api ( array(
        'method' => 'users.setStatus',
     'status' => 'Hi 
this new status by my app 

     ',
      'uid'    => '21511',/// user_id 
      'session'=>$session,
    ) );


     ?>

【讨论】:

  • 非常感谢 :) 但是在 stackoverflow 上读了一点之后,我看到了这篇文章:stackoverflow.com/a/15948611/2466312 所以我认为你的(好的)解决方案不再起作用了:/ ??
猜你喜欢
  • 2011-07-15
  • 2018-10-14
  • 2018-02-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多