Facebooki lehele postituste edastamine kodulehelt

9586 vaatamist
  1. Brunn

    2014-02-14 Administrator Estonia

    Twitter Facebookiga ühendatuks:
    https://support.twitter.com/articles/31113-using-twitter-with-facebook
    ja edasi kasutada:
    http://www.brunn.ee/277-twitterisse-postitamine-oauth-php5-5
    Veel üks võimalus:
    https://www.facebook.com/twitter/

  2. Brunn

    2014-02-16 Administrator Estonia

    Kood on justkui ilus ja lihtne, aga aplikatsiooni seadistamine ise paraku mitte...

    <?php
      require_once('facebook.php');
    
    // initialize Facebook class using your own Facebook App credentials
    // see: https://developers.facebook.com/docs/php/gettingstarted/#install
    $config = array();
    
    $config['appId'] = '46097233400...................';
    $config['secret'] = '33af4388528...................';
    $config['fileUpload'] = false; // optional
     
    $fb = new Facebook($config);
     
    // define your POST parameters (replace with your own values)
    $params = array(
      "access_token" => "460972334006118|.........................", // see: https://developers.facebook.com/docs/facebook-login/access-tokens/
      "message" => "Here is a blog post about auto posting on Facebook using PHP #php #facebook",
      "link" => "http://www.pontikis.net/blog/auto_post_on_facebook_with_php",
      "picture" => "http://i.imgur.com/lHkOsiH.png",
      "name" => "How to Auto Post on Facebook with PHP",
      "caption" => "www.pontikis.net",
      "description" => "Automatically post on Facebook with PHP using Facebook PHP SDK. How to create a Facebook app. Obtain and extend Facebook access tokens. Cron automation."
    );
     
    // post to Facebook
    // see: https://developers.facebook.com/docs/reference/php/facebook-api/
    try {
      $ret = $fb->api('/bitikas/feed', 'POST', $params);
      echo 'Successfully posted to Facebook';
    } catch(Exception $e) {
      echo $e->getMessage();
    }
    ?>
  3. Brunn

    2014-02-16 Administrator Estonia
    <?php
    require "facebook.php";
    $PAGE_ID = "sinu hallatava lehekülje id";    
    $FACEBOOK_APP_ID = "sinu loodud aplikatsiooni id"; 
    $FACEBOOK_SECRET = "sinu loodud aplikatsiooni app secret";
    $ACCESS_TOKEN="selle saad siit https://developers.facebook.com/tools/explorer";
    $PAGE_TOKEN = "";
    
    $facebook = new Facebook(array(  
        'appId'  => $FACEBOOK_APP_ID, 
        'secret' => $FACEBOOK_SECRET,  
        'cookie' => true,  
    ));  
    
    $post = array('access_token' => $ACCESS_TOKEN);
    
    try {
      $res = $facebook->api('/me/accounts','GET',$post);
        if (isset($res['data'])) {
          foreach ($res['data'] as $account) {
             if ($PAGE_ID == $account['id']) {
                $PAGE_TOKEN = $account['access_token'];
                break;
             }
          }
       }
    } catch (Exception $e){
       echo $e->getMessage();
    }
    
    $message = "Proovipostitamine facebooki lehele ja nii et ka töötab";
    $post = array('access_token' => $PAGE_TOKEN, 'message' => $message);  
    
    try{  
       $res = $facebook->api("/$PAGE_ID/feed","POST",$post);           
    } catch (Exception $e){  
       echo $e->getMessage();  
    }
    ?>