1

こんにちは私はこのコードを使用して、$ gg_fbidにidを指定することにより、特定のユーザーにフィードを送信しています。Facebookアプリケーションを介してフィードを送信し、PHPSDKのFacebookアプリケーションを使用してすべてのユーザーにトークンにアクセスする方法はありますか。 はい、それは私が望んでいることです、それは可能ですか、それとも私は彼らのIDを保存するために別のデータベースを作成する必要があります

  require_once("fb/facebook.php");

  $gg_fbid='100004012849319';

    $facebook = new Facebook(array(
  'appId'  => 'xxxxxxxxxxxxxxxxxx',
  'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxx',
));


  $attachment = array
 (
 'access_token'=>$facebook->getAccessToken(),
 'message' => 'This Page is awesome.',
 'name' => 'Must Like It',
 'caption' => 'Dailyjokes',
 'link' => 'http://facebook.com/wtfdailyjokes/',
 'description' => 'Awesome Picture',
 'picture' => 'https://www.facebook.com/photo.php?fbid=264680606974256&set=a.206648236110827.41772.206637039445280&type=1&relevant_count=1'
 );
 $result = $facebook->api($gg_fbid.'/feed/','post',$attachment);
4

2 に答える 2

1

アクセストークンのデータベースがある場合は、それらを取得して繰り返し処理し、アプリユーザーのウォールに投稿できます。

<?php
// instantiate Facebook SDK with your app's credentials
// do database query; fetch access tokens and store in an array called $access_tokens;

foreach ($access_tokens as $access_token) {
    try {
        $facebook->api('/me/feed', array(
            'access_token' => $access_token,
            'message' => 'This Page is awesome.',
            // and the rest of your details
        ));
    }
    catch (FacebookApiException $e) {
        // an error occurred
    }
}
于 2012-08-01T18:52:13.033 に答える
1

イベントや何かについて、Facebook アプリケーションを使用してユーザーのウォールに直接投稿する方法はありません。それが自分の質問に答える理由です。これが機能するには、Facebook 許可の publish_stream が必要です。/

私のコードのようにアプリケーションを使用するときは、ユーザーのデータベースを作成する必要があります

        $facebook = new Facebook(array(
  'appId'  => 'xxxxxxxxxxxxxxx',
  'secret' => 'xxxxxxxxxxxxxxxxxxxxxx',
));
$args = array(
    'message'   => 'Your Message to user Wall',
    'link'      => 'http://apps.facebook.com/lxxxxxxxx',
    'caption'   => ' Use this Awesome application or Like this Page.',
    'picture'      => 'http://xxxxx.png',



);
$post_id = $facebook->api("/me/feed", "post", $args);


  define('db_user','username);
  define('db_password','password');
  define('db_host','localhost');
  define('db_name','database name');

  // Connect to MySQL
  $dbc = @mysql_connect (db_host, db_user, db_password) OR die ('Could not connect to  MySQL: ' . mysql_error() );
    // Select the correct database
   mysql_select_db (db_name) OR die ('Could not select the database: ' . mysql_error() );


  $me = $facebook->api('/me'); 

        $dbcheck = mysql_query("SELECT * FROM users WHERE oauth_provider = 'facebook' AND     oauth_uid = ". $me['id']);  
 $dbr = mysql_fetch_array($dbcheck);  

if(empty($dbr)){ 

  $db=mysql_query("INSERT INTO users (oauth_provider, oauth_uid, username) VALUES ('facebook', {$me['id']}, '{$me['name']}')  ");

}

SO 詳細を伝えるために私の元のコードを投稿します。

これは、ユーザーが最初にアプリケーションを開いたときのコードです。この $args はユーザー ウォールにポストされ、ID とユーザー名がデータベースに保存されます。

将来的には、アプリケーションを使用していて、許可も与えられているユーザー ウォールに何か投稿したい場合は、ウェブサイトや Facebook ファン ページを宣伝することができます。

最後に、これが実際にどのように起こったか。マーティン氏が言っているように、10 人のユーザーには 10 個のアクセス トークンが必要ですが、アプリケーションから投稿する場合、アプリケーション トークンは一度にすべてのユーザーのウォールに投稿するために使用されるため、アプリケーションの単一のアクセス トークンを使用して投稿できます。あなたのアプリがそれを持っていれば、百万人のユーザーに。このリンクを使用してアプリケーションのアクセストークンを取得する方法

https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=xxxxxxxxx&client_secret=xxxxxxxxxxxxxxxxxxxxxxxx

その後、配列内のすべてのIDを取得し、同じコードを実行して、forループを使用してすべてのユーザーウォールに投稿するか、とにかく使用したコードを提供します。

<?php 

 require_once("fb/facebook.php");

    $facebook = new Facebook(array(
  'appId'  => 'xxxxxxxxxx',
  'secret' => 'xxxxxxxxxxxxxxxxxx',
));


$x=array("100001944919003","100000968648478","100001672538252","100003924282886");

$y=0;


while($y<=3){

     $posting_fbid=$x[$y];

     $attachment = array
 (
 'access_token'=>'access token from the url from the graph api',
 'message' => 'This Page is awesome.',
 'name' => 'DailyJokes-Must Like It',
 'caption' => 'Dailyjokes',
 'link' => 'http://facebook.com/wtfdailyjokes/',
 'description' => 'Awesome Picture',
 'scope' => 'publish_stream',
 'picture' => 'https://www.facebook.com/photo.php?fbid=264680606974256&set=a.206648236110827.41772.206637039445280&type=1&relevant_count=1'
 );

  $result = $facebook->api($posting_fbid.'/feed/','post',$attachment);

    echo 'successful for id '.$posting_fbid.'<br>';

    $y++;

}


  ?>
于 2012-10-08T07:56:41.017 に答える