我完全沮丧与我的第一个Facebook应用程序项目。我遇到了一些似乎是一件简单任务的重大问题。Facebook:在页面发布页面问题(访问令牌/ PHP)
我想在我的服务器上设置一个cron作业(简单),它将在Facebook页面(不是我的个人档案)上张贴一些聪明的东西,并且它应该作为页面发布。我将自己编入一个角落,现在完全混淆了......请任何人帮忙吗? “OAuthException:错误校验应用程序”
我一直通几乎每一个错误信息,我现在被困在
这是我现在有:
的第一个PHP - >获取新的访问令牌为我的页面访问。这部分似乎工作正常,因为我得到下一个页面调用并接收新的访问令牌。
<?php
require_once 'facebook.php';
$app_id = "1234....";
$app_secret = "5678....";
$my_url = "http://.../next.php";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
// known valid access token stored in a database
$access_token = "abc....";
$code = $_REQUEST["code"];
// If we get a code, it means that we have re-authed the user
//and can get a valid access_token.
if (isset($code)) {
$token_url="https://graph.facebook.com/oauth/access_token?
client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret
. "&code=" . $code . "&display=popup";
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$access_token = $params['access_token'];
}
// Attempt to query the graph:
$graph_url = "https://graph.facebook.com/me?"
. "access_token=" . $access_token;
$response = curl_get_file_contents($graph_url);
$decoded_response = json_decode($response);
//Check for errors
if ($decoded_response->error) {
// check to see if this is an oAuth error:
if ($decoded_response->error->type== "OAuthException") {
// Retrieving a valid access token.
$dialog_url= "https://www.facebook.com/dialog/oauth?"
. "client_id=" . $app_id
. "&redirect_uri=" . urlencode($my_url);
echo("<script> top.location.href='" . $dialog_url
. "'</script>");
} else {
echo "other error has happened";
}
} else {
// success
echo("success" . $decoded_response->name);
}
function curl_get_file_contents($URL) {
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
$err = curl_getinfo($c,CURLINFO_HTTP_CODE);
curl_close($c);
if ($contents) return $contents;
else return FALSE;
}
?>
Next php - >阅读访问令牌并发布在墙上。我从查询字符串中获取访问令牌,但为什么会收到错误消息。我的ID,秘密和页面ID都是为了...
<?php
require_once 'facebook.php';
$app_id = "1234....";
$app_secret = "5678....";
$page_id = "0909....";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$access_token = $_GET['code'];
echo($access_token);
try {
$attachment = array(
'access_token' => $access_token,
'message'=> "Hello World"
);
$result = $facebook->api('/'.$page_id.'/feed','POST',
$attachment);
var_dump($result);
} catch(Exception $e) {
echo $e;
}
?>
我敢肯定有一个简单的方法,这样做....和方式其实就是使它的工作! 任何帮助表示赞赏!
我跟着这个脚本 Update facebook page status from that page itself 这 https://developers.facebook.com/blog/post/500
谢谢。
我在你的代码不清楚(不是PHP dev的我自己)为你在哪里提取的页面访问令牌就像http://stackoverflow.com/questions/4309154/update-facebook- page-status-from-that-page-itself-graph-api-php。 – DMCS 2012-01-30 20:31:51
我在第一个脚本中获取访问令牌,因为当我使用从链接的示例中获取的访问令牌时,令牌限制为2小时。第一个脚本检查旧的访问令牌 - >意识到它是旧的 - >并返回给我一个新的查询字符串... – Peter1178373 2012-02-01 13:09:06