简体   繁体   中英

Facebook auto post on wall after like

So basically i am building a script for a client which is used as an iframe in his page. What it should do is when a user likes his page then he can see the contents and the "app" should auto post something to his wall (sounds like spam but im not sure if there is a problem with that). so i got the first bit working but for the love of god i cant make the second part.. here's my code

<? require 'facebook.php';
$app_id = "my_appid";
$app_secret = "my_secret";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$signed_request = $facebook->getSignedRequest();
function parsePageSignedRequest() {
    if (isset($_REQUEST['signed_request'])) {
      $encoded_sig = null;
      $payload = null;
      list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
      $sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
      $data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true));
      return $data;
    }
    return false;
  }
  if($signed_request = parsePageSignedRequest()) {
    if($signed_request->page->liked) {
      echo "This content is for Fans only!";    
    } else {
      echo "Please click on the Like button to view this tab!";
    }
  }

?>

i tried adding this on the "logged state"

$result = $facebook->api( '/me/feed/','post',
        array('access_token' => $app_secret,
              'message' => 'Playing around with FB Graph..')
    );

with no luck as i get an error. please let me know if you can help. thanx

The first part, liking a url and autoposting to users stream has nothing todo with the code you show. this code is just a simple fan gateway.

no user is logedin.

The steps you would need are:

  • let the user login and ask for publish_stream permission ( more info )
  • set a listener on the edge.create event ( more info )
    • if this event fires send an ajax call to server to make the post. ( more info )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM