mardi 3 février 2015

Facebook Graph API - PHP - Can't post to certain pages


Vote count:

0




Question: Why is it giving this error and how do I resolve it?


I am using the Facebook Graph API to post a reply/comment to specific posts that I have already created in specific Facebook groups. I am a currently a member of the group and can reply/comment manually to my post.


The app is not currently "live" in the developer interface.


39 of the 80 some odd posts give this error:


Array ( [error] => Array ( [message] => (#200) Permissions error [type] => OAuthException [code] => 200 ) )


Access Token Code



//Gets Facebook Token ID for use in facebook-poster.php

session_start();
$app_id = "...";
$app_secret = "....";
$my_url = "......"; // redirect url

$code = $_REQUEST["code"];

if(empty($code)) {
// Redirect to Login Dialog
$_SESSION['state'] = md5(uniqid(rand(), TRUE)); // CSRF protection
$dialog_url = "http://ift.tt/1ep6vXc"
. $app_id . "&redirect_uri=" . urlencode($my_url) . "&state="
. $_SESSION['state'] . "&scope=publish_stream,publish_actions,read_friendlists,email";


echo("<script> top.location.href='" . $dialog_url . "'</script>");
}
if($_SESSION['state'] && ($_SESSION['state'] === $_REQUEST['state'])) {
$token_url = "http://ift.tt/JH6Whd?"
. "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret . "&code=" . $code;

$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$longtoken=$params['access_token'];
}

echo $longtoken;

?>


Comment Posting Snippet



$fbId = array ( '1893939', '919191');


echo "
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '432961683519842',
xfbml : true,
version : 'v2.2'
});
};

(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = \"//connect.facebook.net/en_US/sdk.js\";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
</HEAD>
<BODY>";


foreach ($fbId as $ID) {

$i++; //Increment counter for sleep timer.

$attachment = array(
'access_token' => $accessToken,
'message' => "Message",
);

// set the target url

$url = 'http://ift.tt/1xQ2IHl' . $ID . '/comments';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$go = curl_exec($ch);
echo "Facebook ID: <a href=http://ift.tt/eIlFV0". $ID .">". $ID ."</a> >> Status: ". $go ."<BR>";
curl_close ($ch);

$go = json_decode($go, TRUE);

echo "JSON Decode 1: <BR>";
print_r($go);

if( isset($go['id']) ) {
$url = "http://ift.tt/1DuJUjG['id']}/comments";

$attachment = array(
'access_token' => $accessToken,
'message' => "Bump". rand(0,5000) ."...",
);

// set the target url
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$comment = curl_exec($ch);
curl_close ($ch);
$comment = json_decode($comment, TRUE);
print_r($comment);
echo "<BR><HR>";
}

if ($i % 20 == 0) { echo "<HR>Sleep<HR><BR>"; sleep(20); }
}




foreach ($fbId as $ID) {
echo "<a href=http://ift.tt/eIlFV0". $ID .">". $ID ."</a> &nbsp;&nbsp; | &nbsp;&nbsp;";
if ($i % 10 == 0) { echo "<BR>"; }
}
}


asked 25 secs ago

Travis

161






Facebook Graph API - PHP - Can't post to certain pages

Aucun commentaire:

Enregistrer un commentaire