duandi8613 2013-06-04 10:13 采纳率: 100%
浏览 456

Facebook API登录时仍然出现“参数app_id is required”错误

I cannot get the FB API example to work. I have my app registered (tried both sandbox and standard mode), I provided appId and appSecret when instantiating the facebook object, but when I click the login link I still get the error The parameter app_id is required.

My php code (in config.php I define APP_ID and APP_SECRET):

<?php
require 'config.php';

//Including facebook php sdk file
require '../classes/Facebook.php';

//Creating our application instance
$facebook = new Facebook(array(
        'appId' => APP_ID,
        'secret' => APP_SECRET
));


//Get User ID
$user = $facebook->getUser();

if ($user) {
    try {
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $facebook->api('/me');
    } catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
    }
}


// Login or logout url will (depending on current user state)
if ($user) {
    $logoutUrl = $facebook->getLogoutUrl();
} else {
    $loginUrl = $facebook->getLoginUrl();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Test FB</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <script type="text/javascript" src="js/jquery-1.7.2.js"></script>
    <script type="text/javascript" src="bootstrap/js/bootstrap.js"></script>
</head>
<body>

    <?php if ($user): ?>
        <img src="https://graph.facebook.com/<?php echo $user; ?>/picture" style="width:25px; height: 25px; margin-top: 7px;" />
        <a style="color:#fff;"><?php echo $user_profile['name'] ?></a>
    <?php endif ?>

    <?php if ($user): ?>
        <a href="<?php echo $logoutUrl; ?>">Logout</a>
    <?php else: ?>
        <a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
    <?php endif ?>

</body>
  • 写回答

1条回答 默认 最新

  • douzhang1852 2013-06-04 12:17
    关注

    put this in config.php

    define("APP_ID", "3983####90");
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题