php Facebook require_login 不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3000166/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 08:22:47  来源:igfitidea点击:

Facebook require_login not working

phpfacebookfacebook-graph-api

提问by Odyss3us

I am having some trouble with my little facebook application, I keep getting this friggin error, "Fatal error: Call to undefined method Facebook::require_login()", now the funny bit is that my exact same code is working for other people, but not for me, here is the code.

我的小 facebook 应用程序遇到了一些麻烦,我不断收到这个该死的错误,“致命错误:调用未定义的方法 Facebook::require_login()”,现在有趣的是我的完全相同的代码对其他人有效,但不适合我,这是代码。

<?php
require_once( "facebook-php-sdk/src/facebook.php" );
$api_key = "my_api_key";
$secret = "my_secret_key";

$facebook = new Facebook( $api_key, $secret );
$user_id = $facebook->require_login();

echo "Hello World";
echo "Current logged in as <fb:name uid=\"$user_id\" />";
?>

As you can see it is a simple hello USER application, but for some reason this REFUSES to work for me, so if anyone can help out that would be great, thanx in advance!

正如您所看到的,这是一个简单的 hello USER 应用程序,但由于某种原因,它拒绝为我工作,所以如果有人能提供帮助,那就太好了,提前谢谢!

回答by Peter Bailey

Are you using the newest version of the PHP sdk?

您使用的是最新版本的 PHP sdk吗?

Facebook::require_login()is a method from the old SDK.

Facebook::require_login()是旧 SDK 中的一种方法。

The new SDK (published in conjunction with the Graph API) is not backwards compatible.

新的 SDK(与 Graph API 一起发布)不向后兼容。

The notion of requiring a login doesn't even exist anymore - you just obtain the user's ID as such.

要求登录的概念甚至不再存在 - 您只需获取用户 ID。

$user_id = $facebook->getUser();

回答by k4t434sis

Try out this function:

试试这个功能:



function appInstance($fbconfig){
    try{
        include_once "facebook.php";
    }
    catch(Exception $o){
        echo '<pre>';
        print_r($o);
        echo '</pre>';
    }
    $facebook = new Facebook(array(
      'appId'  => $fbconfig['appid'],
      'secret' => $fbconfig['secret'],
      'cookie' => true,
    ));
    $session = $facebook->getSession(); 
    $fbme = null;
    // Session based graph API call.
    if ($session) {
      try {
        $uid = $facebook->getUser();
        $fbme = $facebook->api('/me');
      } catch (FacebookApiException $e) {
          //d($e);    //debug
          'Facebook took too long to respond, try again in a few minutes.';
      }
    }
    return $uid;
    return $fbme;
    return $facebook;
}//end appInstance()


after you make the call to that function use $fbme to pull whatever info you got from your perms like so $firstName=$fbme['first_name']or $email=$fbme['email'].

在您调用该函数后,使用 $fbme 提取您从烫发中获得的任何信息,例如 so$firstName=$fbme['first_name']$email=$fbme['email']

回答by cuneyt

a blatant answer, yet, are you on the web domain that you registered your app for on Facebook. if you registered xxxyy.com, you can use your app only there.

然而,一个明显的答案是,您是否在您在 Facebook 上注册您的应用程序的网络域中。如果您注册了 xxxyy.com,则只能在那里使用您的应用程序。

回答by k4t434sis

Did you perhaps double check that your domain that is registered with facebook is the same as the dev site you are working on? Probably is, but that one will get you if you don't pay attention. Got me first time around on migration :]

您是否仔细检查过您在 facebook 上注册的域与您正在处理的开发站点相同?可能是,但如果你不注意,那一个会抓住你。让我第一次了解迁移:]