Facebook PHP SDK: getUser returns 0 on first call

January 31, 2013 at 14:30

The problem: a facebook login doesn't always work. Although the user has authenticated the app, getUser returns 0. So, the user clicks a LOGIN button and is being redirected to $facebook->getLoginUrl. Facebook forces the user to authenticate the app and afterwards redirects back to my page, to login.php to be exact. And this is where I call getUser, expecting to get the current user's facebookUserId. But this didn't work for a fresh user who hasn't been to my site just yet. What my script now did was to redirect back to getLoginUrl, which in turn redirects back to login.php and so on, which quickly makes the browsers stop and claim a "redirect error" (gee, I hope that's the right translation..). By the way, chrome is the first to give in, even before IE. Scary. The solution: a javascript redirect. Instead of doing a php redirect, I show a page which most users shouldnt even see and on this page there's a location.href, leading back to the getLoginUrl. And, strangely enough, that works flawlessly!

Hinterlasse einen Kommentar:
[...] habe ja schonmal einen Artikel zum Thema "getUser liefert 0 zurück" geschrieben, aber seit neuestem hilft mir auch das nicht weiter. Egal was ich auch mache, beim [...]