简体   繁体   English

Facebook PHP SDK getUser()在Windows上的Safari中返回0

[英]Facebook PHP SDK getUser() returning 0 in Safari on Windows

I am working on a Facebook iframe app. 我正在使用Facebook iframe应用。 I am using both the PHP SDK and the JS SDK. 我同时使用PHP SDK和JS SDK。 In my index file I call on the PHP SDK for some information about the user. 在索引文件中,我调用PHP SDK以获得有关用户的一些信息。 This includes the getUser() function, which always works in the index. 这包括getUser()函数,该函数始终在索引中工作。

I have a number of other PHP files, however, that I use to populate divs in the index when the user clicks on certain links. 但是,我还有许多其他PHP文件,当用户单击某些链接时,这些文件用于填充索引中的div。 I am using the FB PHP SDK in each one of these files to ensure that the user is still logged into FB. 我在这些文件的每一个中都使用FB PHP SDK,以确保用户仍登录到FB。 That is, when these files are executed I call on the getUser() function to get the user's ID and determine if the person is still logged in. I inject the content of these PHP files into the divs in index via jQuery's load() function. 也就是说,在执行这些文件时,我调用getUser()函数来获取用户的ID并确定该人是否仍在登录。我通过jQuery的load()函数将这些PHP文件的内容注入到div中的div中。 。

This works under FFox, Opera, IE, and Chrome just fine but under certain installations of Safari it does not. 可以在FFox,Opera,IE和Chrome下正常运行,但在某些Safari安装下则不能。 Specifically, I've had major issues with 5.1.5 (7534.55.3). 具体来说,我在5.1.5(7534.55.3)中遇到了主要问题。 When the PHP files get called by the jQuery load function under this version of Safari the getUser() function always seems to return 0 (zero). 在此版本的Safari下,当jQuery load函数调用PHP文件时,getUser()函数似乎总是返回0(零)。 I'm assuming this has something to do with the session cookies? 我假设这与会话Cookie有关? I really don't know and was hoping someone on here could shed some light on this for me. 我真的不知道,希望有人能为我提供一些启示。 Thanks.. 谢谢..

you can add this to your site: 您可以将其添加到您的网站:

<?php
$uid = $facebook->getUser();

if ($uid==0) {

    $params = array(
      'scope' => 'read_stream, friends_likes',
      'redirect_uri' => 'https://www.myapp.com/post_login_page'
    );

    $loginUrl = $facebook->getLoginUrl($params);
    echo '<a href="'.$loginUrl.'">You need first to Login</a>';
    exit();

} else {

     //Continue your site code

} 


?>

Not sure if this is an issue any more but it impacted my Safari FB app development for some time. 不知道这是否是一个问题,但是一段时间以来它影响了我的Safari FB应用程序开发。 Check out this SA answer to fix it, I pretty much followed it exactly and it worked. 看看这个SA答案来解决它,我几乎完全遵循了它,并且有效。 Missing cookies on iframe in safari 5.1.5 Safari 5.1.5中的iframe缺少Cookie

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

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