Php Facebook connect API,用户id始终为空,我可以';我无法恢复我的个人资料
这是我在stackoverflow上的第一篇文章,我希望我能对我的问题有正确的答案,因为我到处都在研究以找到解决方案,但没有什么有用的…所以我正在做一个zend项目,在我的Facebookcontroller.php中,我使用了成功连接到我的网站并获取有关profil的信息所需的所有函数。事实上,这是我第一次使用此API,所以我选择使用php SDK。问题是我的$uid中总是有一个大“0”,所以我无法恢复我的个人资料,也无法将这些信息存储在我的数据库中……我希望这很清楚,这是我控制器的代码。关于facebook应用程序,我在www.developer.facebook.com中创建了一个,它工作正常,我可以进行身份验证,然后被重定向到我的index.php。感谢您的帮助Php Facebook connect API,用户id始终为空,我可以';我无法恢复我的个人资料,php,facebook-graph-api,zend-framework,facebook-php-sdk,Php,Facebook Graph Api,Zend Framework,Facebook Php Sdk,这是我在stackoverflow上的第一篇文章,我希望我能对我的问题有正确的答案,因为我到处都在研究以找到解决方案,但没有什么有用的…所以我正在做一个zend项目,在我的Facebookcontroller.php中,我使用了成功连接到我的网站并获取有关profil的信息所需的所有函数。事实上,这是我第一次使用此API,所以我选择使用php SDK。问题是我的$uid中总是有一个大“0”,所以我无法恢复我的个人资料,也无法将这些信息存储在我的数据库中……我希望这很清楚,这是我控制器的代码。关于
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package controller
* @subpackage Facebook
* @copyright Copyright (c) 2005-2010 PHPSA . (http://www.phpsa.co.za)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: FacebookController.php
*/
class FacebookController extends Zend_Controller_Action
{
public function indexAction(){
require_once 'API/facebook.php';
$appId = 'xxxxxxxxx';
$appSecret = 'xxxxxxxxxxxxxxxxxxxxxxx';
// Create your Application instance (replace this with your appId and secret).
$facebook = new Facebook(
array(
'appId' => $appId,
'secret' => $appSecret,
'fileUpload' => true,
'cookie' => true
));
// Get User ID
$uid = $facebook->getUser();
if ($uid)
{
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$uid = null;
}
}
// Login or logout url will be needed depending on current user state.
if ($uid)
{
$logoutUrl = $facebook->getLogoutUrl();
}
else
{
$loginUrl = $facebook->getLoginUrl(
array(
'canvas' => 1,
'fbconnect' => 0,
'scope' =>'email,user_photos,user_birthday,offline_access',//these are the extended permissions you will need for your app, add/remove according to your requirement
'redirect_uri' => 'http://localhost:82/myProject/public/index.php',//this is the redirect uri where user will be redirected after allow,
));
}
if ($uid)
{
mysql_connect("localhost", "root", "");
mysql_select_db("export");
$result = mysql_query("INSERT INTO users(id, firstname, lastname, birthday, email, facebook,gender) VALUES('','$user_profile[first_name]','$user_profile[last_name]','$user_profile[birthday]', '$user_profile[email]','$user_profile[id]','$user_profile[gender]')");
if (!$result)
{
die('Requête invalide : ' . mysql_error());
}
}
else
{
//redirect user to loginUrl
echo "<script>parent.location = '".$loginUrl."';</script>";
}
}
}
?>
请删除您的appId和secret以防止不必要的访问…您使用的是什么版本的Facebook PHP SDK?感谢您的回复,我正在使用PHP SDK v3.0.0,有人能帮我吗?我需要你的帮助,我没有找到解决这个问题的方法。我想知道我的网站是否应该通过ssl认证来获取用户信息?facebook是否可能阻止对未经ssl认证的应用程序进行任何认证?