我正试图将数据从facebook图保存到我的数据库。我不确定我的错误是在facebook部分还是php部分。
当我运行代码时,屏幕上什么也没有发生。没有错误信息,没有转发到其他位置(通过报头),没有数据保存到数据库。
附代码:
if ($cookie)
{
$user = json_decode(file_get_contents('https://graph.facebook.com/me?access_token='.$cookie['access_token']),true);
if ($user)
{
// Connect to database
mysql_connect('localhost', 'xxxxx', 'xxxxxx');
mysql_select_db('xxxxx');
$result = mysql_query("INSERT INTO users (xxxx, xxxx) VALUES ('".$user['data']['id']."', '"$user['data']['name']."');");
if ($result)
{
// If User successfully stored - redirect to update or post on Facebook wall
header("Location: http://xxxxxxx.com/xxxxxxx.php");
exit;
}
else
{
// If Error in storing
echo '$result is empty';
}
}
else
{
// If error in parsing
echo '$user is empty';
}
}
else
{
// If error in authentication status
echo '$cookie is empty';
}
有人知道吗?
https://graph.facebook.com/me无法处理文件获取内容。您需要指定一个facebook用户/页面的Id来获取内容。
如果您没有得到任何输出,这可能意味着您的脚本很早就崩溃了。您是否使用支持json_decode的PHP版本?那将是我的第一张支票。否则,试着把它放在脚本的最上面,看看是否能找到任何线索:
error_reporting(E_ALL);
ini_set("display_errors", 1);