dql123000 2014-05-22 21:12
浏览 101
已采纳

Facebook php SDK - 简单的数据提取

I'm trying to integrate my facebook app with PHP. What I need to do is have users go to the app-page, authenticate the app and then somehow I want to end up with a variable that contains the info I need so I can store it in MySQL.

I downloaded the facebook SDK, but I cannot figure out how to make it work. All the examples I can find refer to a file called facebook.php - but there is no such file in the SDK (maybe the changed it?).

I managed to get it working with JavaScript, but I don't know how to get from JavaScript to php (the user object, that is).

I would prefer to just run it entirely through php. What I'm trying to do is very simple, but I don't understand what I'm doing wrong. The following, for instance, does not work:

<?php
FacebookSession::setDefaultApplication('appid', 'appsecret');
require facebook-php-sdk-v4-master\src\Facebook\FacebookCanvasLoginHelper.php;

$helper = new FacebookCanvasLoginHelper();
try {
  $session = $helper->getSession();
} catch(FacebookRequestException $ex) {
  echo "error";
} catch(\Exception $ex) {
  echo "error 2";
}
if ($session) {
    echo "logged in";
}

?>

Gives PHP Fatal error: Class 'FacebookSession' not found in

Where do I go? I don't think the Facebook getting started guide is helpful at all. It just starts out with "you have to do this" (what I did above) - but that doesn't work?

  • 写回答

2条回答 默认 最新

  • doubo7131 2014-05-22 21:29
    关注

    Looks like they changed the whole SDK for PHP 5.4.

    Well there's a few options, you could go with the older SDK and all those tutorials you found will work for that. Or you could learn some new things!

    I suggest that if you want to use the new Facebook SDK, you go ahead an learn about composer first, it makes including libraries a piece of cake and all you'd have to do is include the autoloader at the top of the file. Once done, you can just follow the example and it should work.

    If you don't want to learn composer, you'll have to include all the required files manually. Here's a basic example.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划