php
  • facebook
  • facebook-graph-api
  • 2012-08-01 38 views 1 likes 
    1

    您好我使用此代碼通過提供$ gg_fbid中的id發送飼料給特定用戶。 是否有任何方法通過Facebook應用程序和訪問令牌將所需的訂閱源發送給在PHP SDK中使用Facebook應用程序的所有用戶。 是,這是我想要的東西,是可能的,或者我應該做一個單獨的數據庫來存儲它們的ID需要在所有用戶發佈飼料時間表通過Facebook的應用程序,他們已經授權

    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); 
    
    +0

    我不確定你想要做什麼。你只是想張貼到你的Facebook應用程序的每個用戶的飼料? – 2012-08-01 17:43:33

    +0

    是這就是我想要的,是可能的,或者我應該做一個單獨的數據庫來存儲他們的ID。 – Abhishek 2012-08-01 17:45:58

    +0

    如果您爲每個驗證您的應用的人存儲訪問令牌,那麼您可以使用該令牌,因爲解碼時包含用戶的ID。所以你可以對所有的訪問令牌做一個'foreach()',並且做你的API調用來發布到那個用戶的牆上。 – 2012-08-01 18:37:53

    回答

    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個用戶,但如果您從應用程序發佈而不是正確的應用程序,則應用程序令牌不能正確發佈,所以使用Application的單個訪問令牌可以發佈如果您的應用程序具有該功能那麼如何使用這個鏈接

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

    之後得到應用的訪問令牌獲取在陣列中的所有ID和,還是要執行相同的代碼使用循環張貼在所有用戶牆上還我給我的代碼,我使用。

    <?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++; 
    
    } 
    
    
        ?> 
    
    +0

    阿布舍克Gahlot謝謝你,但有一個與你的第一個代碼..致命錯誤問題:未捕獲OAuthException:活動的訪問令牌必須用於查詢當前用戶的信息。在1243行扔在/ home/megapixe/public_html/quran/facebook/base_facebook.php? – 2012-12-09 11:30:16

    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 
        } 
    } 
    
    +0

    再次感謝,它會真的幫助我很多。只需要獲取id並在foreach語句中替換即可。 – Abhishek 2012-08-01 19:22:49

    +0

    我不認爲你明白。訪問令牌標識用戶,因爲它對特定用戶是唯一的。因此,當您發佈到Facebook時,Facebook將解密該令牌並知道哪個用戶的牆壁要加入。 – 2012-08-02 07:37:06

    +0

    我明白你在說什麼,因爲我現在用的應用程序已經通過publish_Stream並通過應用程序ID和應用程序的祕密,我可以張貼獲准馬丁,,訪問令牌不是一般的在我的情況很重要。 仍然需要權限的訪問令牌。 – Abhishek 2012-08-02 12:37:14

    相關問題