Facebook authentication in function - getUser() returns 0

前端 未结 5 996
余生分开走
余生分开走 2021-01-18 18:33

I\'m trying to make a function in my controller to post an album to Facebook. Every time the function is accessed, I\'m redirected to REDIRECT_URI, as if the $userid=0, eve

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-18 19:07

    By default the Facebook class uses PHP sessions to store the authentication state of the user. There are four session variables that may be used:

    • fb_{appid}_user_id: Facebook user ID
    • fb_{appid}_code: authorization code that needs to be exchanged for an access token
    • fb_{appid}_access_token: access token that can be used to make API calls
    • fb_{appid}_state: CSRF token

    Check that your PHP sessions are configured and working correctly.

    • By default the cookie name is PHPSESSID; you should see that being set in your browser.
    • If you are load balancing across multiple servers you will need a solution that lets you share session state across those servers.
    • You cannot output any text before starting the session (done automatically if needed when instantiating the Facebook object). You might want to try putting this as the very first line of your function:

      if (!session_id()) { session_start(); }
      

提交回复
热议问题