2013-06-08 15 views
5

私のアプリが代わりにユーザーの壁に投稿されたい(たとえば、広告など)。私は毎週私のサーバー上でcronジョブを実行するPHPスクリプトを作成することを考えています。 自分のデータベースにユーザーIDがあります。 今、私はスクリプトがユーザーIDを取得し、ユーザーの壁に投稿したがっています。 (もちろん、ユーザーがまだアプリをインストールしていて、公開ストリームを許可している場合)ユーザーの壁に自動的に投稿する(Facebookブックアプリ)

これをトリガするスクリプトを作成することは可能ですか?
$ 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(); 
    } 

    } 

?> 
+0

さらに、上記のコードの問題は、コミュニティにあなたのためにプログラムすることを求めていますか? –

+0

これをトリガするスクリプトを作成することは可能ですか? $ post = $ facebook-> api( "/ $ user1/feed"、 "POST"、$ params); $ post = $ facebook-> api( "/ $ user2/feed"、 "POST"、$ params);等...? –

答えて

4

ため

ありがとう、私はあなたと私のコードを共有することになります。 これは私のために働いた。

データベースからすべてのユーザー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, 
    )); 


    ?> 
+1

ありがとうありがとう:)しかし、stackoverflowで少し読んだ後、私はこのポストを見た:http://stackoverflow.com/a/15948611/2466312だから私はあなたの(良い)ソリューションはもう動作しません:/ ?? –

+1

これはまだ動作します、ありがとう –

関連する問題