duan201444 2009-05-17 23:34
浏览 36
已采纳

链接Facebook Connect

I've started working on integrated Facebook Connect with my app. I have a slight lack of knowledge problem though.

I can perfectly make it so you log into Facebook Connect on my site, etc, shows your details all FB Connect functions work. But, how do I make it so I can store the facebook user ID into my MySQL database as part of the current users information? So how I can auto log them into Facebook Connect if they have granted access?

Thanks!

  • 写回答

4条回答 默认 最新

  • duanhuang3074 2009-06-20 18:15
    关注

    Using the PHP Facebook client library, you should be able to add something this at the top of "the page":

    $api_key = "YOUR APP API KEY";
    $api_secret = "YOUR API SECRET KEY";
    
    $facebook = new Facebook($api_key, $api_secret);
    $facebook_id = $facebook->get_loggedin_user();
    

    If the user is logged in, $facebook_id will be set to their facebook id (BIGINT). If not, it'll be null. Mind that users need to have third-party cookies enabled in their browser for this to work past the intial "connect" call. In that case you can use the API to get the logged in user:

    $facebook->api_client->users_getLoggedInUser();
    

    So basically (pseudo):

    if (!is_null($facebook_id))
    {
        // authenticate user on your site with local cookie or session
        // pull user data from users table by "$facebook_id"
        // if user isn't in the database, create a new row with their facebook id
    }
    else
    {
        // show the connect button?
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog