简体   繁体   English

Facebook应用程式无法正常运作

[英]Facebook app not working properly

I am writing a Facebook app, I would like to show the app only for facebook users and would like to get the user details. 我正在编写一个Facebook应用程序,我只想向Facebook用户显示该应用程序,并希望获取用户详细信息。 I have used the following codes 我使用了以下代码

$facebook = new Facebook(array(
 'appId'  => 'xxxxxx',
 'secret' => 'xxxxxx',
));

$user = $facebook->getUser();

if ($user) {

  try {

  } catch (FacebookApiException $e) {
    error_log($e);
  }
}
else{

  $urlf= $facebook->getLoginUrl(array('scope' => 'user_status,publish_stream'));
  header("Location:".$urlf);
  exit;
}

if ($user) {
  $user_profile = $facebook->api('/me');
}

Here $urlf is giving the correct url, it is working well when I copy paste that url in the browser. 这里$urlf提供正确的url,当我在浏览器中复制粘贴该url时,它运行良好。 But the header location is not working. 但是标题位置不起作用。 This code is residing in the Canvas URL folder. 此代码位于“画布URL”文件夹中。 Now the problem is that header location is not working. 现在的问题是标题位置不起作用。 Please help me to solve it. 请帮我解决。

Try catch is used to try something, and then if there are any errors resolve it properly. Try catch用于尝试某些操作,然后如果有任何错误,请妥善解决。 Your try has nothing in it, so it's worthless. 您的尝试没有任何内容,因此一文不值。 That means nothing happens if $facebook->getUser() works. 这意味着如果$facebook->getUser()有效,则什么也不会发生。

You should sincerely read some books on programming PHP, because it's hard to tell what your code is trying to do. 您应该真诚地阅读一些有关PHP编程的书,因为很难分辨您的代码正在尝试做什么。

It is very hard to guess without any error message, or indication of what's going on. 如果没有任何错误消息或发生什么情况,很难猜测。 But if your $urlf variable is correct, and if redirection is not happening it probably means that there is output before header() is called. 但是,如果您的$urlf变量正确,并且没有发生重定向,则可能意味着 header()调用之前 $urlf输出。

Make sure that header() is called before any output in the page, and it should work. 确保在页面中的任何输出之前调用header() ,并且它应该工作。 If not you will need to debug your script and display PHP errors, using 如果不是这样,您将需要调试脚本并显示PHP错误,请使用

ini_set('display_errors', 1);
ini_set('error_reporting', -1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM