如何在Facebook iframe应用程序中获取Facebook用户的用户ID?
I'm developing a Facebook iframe/Facebook Connect application with PHP client library. In my index page, I check if the user is logged in by using require_login()
.
$user_id = $facebook->require_login($required_permissions = 'user_location,publish_stream,email,read_stream,user_about_me,user_activities,user_birthday,user_events,user_groups,
user_hometown,user_interests,user_likes,user_status,user_photos);
Thus I get the $user_id of the user in that page. But in the subsequent pages, If I use require_login() to get the user_id, some prablem occurs and the page ie not redirected. The page gets refreshing and nothing is displayed.
So I tried using $user_id = $facebook->get_loggedin_user();
but then I dont get the user id in the variable.
If I use $user_id = $_GET[fb_sig_user];
, sometimes I get the value, sometimes I dont. Please suggest me the proper method to get the user_id in other pages too.
我正在开发一个带有PHP客户端库的Facebook iframe / Facebook Connect应用程序。 在我的索引页面中,我使用 user_hometown,user_interests,user_likes,user_status,user_photos); p>
因此我在该页面中获得了用户的$ user_id。 但是在后续页面中,如果我使用require_login()来获取user_id,则会发生一些prablem并且页面没有被重定向。
页面变得清爽,没有显示任何内容。 p>
所以我 尝试使用 如果我使用 require_login() code>检查用户是否已登录。 p>
$ user_id = $ facebook-> require_login( $ required_permissions ='user_location,publish_stream,email,read_stream,user_about_me,user_activities,user_birthday,user_events,user_groups,
code> pre>
$ user_id = $ facebook-> get_loggedin_user(); code>,但后来我没有在变量中获得用户ID。 p>
$ user_id = $ _GET [fb_sig_user]; code>,有时我得到的价值,有时我不。 请建议我在其他页面中获取user_id的正确方法。 p>
div>
I have found the answer. Posting it so that it might help someone else ..
Adding $facebook->require_frame();
before using the $user_id = $facebook->require_login()
syntax in the main page and the $user_id = $facebook->get_loggedin_user();
in the other pages, solves the problem.
For more details refer to this thread: http://forum.developers.facebook.com/viewtopic.php?pid=218858