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条)

报告相同问题?

悬赏问题

  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器