Facebook 应用程序保留以前的用户详细信息

发布于 2024-12-15 18:59:18 字数 305 浏览 3 评论 0原文

我在使用 Facebook Iframe 应用程序时遇到问题。我的问题是,如果用户登录到应用程序,然后注销应用程序并且另一个(不同的)用户登录,则 $facebook->getUser() 返回前一个用户的 id。

我尝试每次将用户发送到登录网址,但它仍然会发生,直到页面刷新一次(第一次登录应用程序需要以前的用户 fb 会话,然后就可以了)。

我能找到的唯一线索是,这是由于 $facebook->getUser() 方法中的持久数据而发生的......

也许有人可以帮助阐明这个问题,因为很多次之后我无法找不到解决办法... 谢谢!

I'm having a problem with a facebook Iframe application. My problem is that if a user logs in to the app, then logs out of the application and another (different) user logs in, the $facebook->getUser() returns the id of the previous user.

I tried to send the user to the login url each time, but it still happens untill the page is refreshed once (first login to app takes the previous user fb session, then its ok).

The only lead I was able to find was that this happens due to the persistent data in the $facebook->getUser() method...

Maybe someone can help shed some light on this matter, as after a lot of times I couldn't find a solution...
Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

要走干脆点 2024-12-22 18:59:18

您正在正确使用 facebook PHP SDK。
在 facebook php sdk 中,当您调用

$facebook->getUser() 方法时,它首先检查它是否是私有变量,如果用户已经设置或没有,这里是方法,

   * Get the UID of the connected user, or 0
   * if the Facebook user is not connected.
   *
   * @return string the UID if available.
   */
  public function getUser() {
    if ($this->user !== null) {
      // we've already determined this and cached the value.
      return $this->user;
    }
    return $this->user = $this->getUserFromAvailableData();
  }

所以如果您是第一次调用,当然 user< /code> 变量为 null

所以现在它调用 getUserFromAvailableData();方法

   /** * Retrieve the signed request, either from a request parameter or,
   * if not present, from a cookie.
   *
   * @return string the signed request, if available, or null otherwise.
   */
  public function getSignedRequest() {
    if (!$this->signedRequest) {
      if (isset($_REQUEST['signed_request'])) {
        $this->signedRequest = $this->parseSignedRequest(
          $_REQUEST['signed_request']);
      } else if (isset($_COOKIE[$this->getSignedRequestCookieName()])) {
        $this->signedRequest = $this->parseSignedRequest(
          $_COOKIE[$this->getSignedRequestCookieName()]);
      }
    }
    return $this->signedRequest;
  }

和 getSignedRequestCookieName() 返回,

protected function getSignedRequestCookieName() {
    return 'fbsr_'.$this->getAppId();
   }

因此现在 getSignedRequest() 函数首先检查是否设置了签名请求,如果没有设置它从 Cookie 获取签名请求

如果最后你不想获取以前的用户 ID,只需删除名为 ''fbsr_'+YourApplicationID' 的 cookie

You are using facebook PHP SDK right.
In facebook php sdk when you call the

$facebook->getUser() method it first check it it's private variable if user already set or not here is the method

   * Get the UID of the connected user, or 0
   * if the Facebook user is not connected.
   *
   * @return string the UID if available.
   */
  public function getUser() {
    if ($this->user !== null) {
      // we've already determined this and cached the value.
      return $this->user;
    }
    return $this->user = $this->getUserFromAvailableData();
  }

so if you are call the first time of-course user variable is null

so now it call getUserFromAvailableData(); method

   /** * Retrieve the signed request, either from a request parameter or,
   * if not present, from a cookie.
   *
   * @return string the signed request, if available, or null otherwise.
   */
  public function getSignedRequest() {
    if (!$this->signedRequest) {
      if (isset($_REQUEST['signed_request'])) {
        $this->signedRequest = $this->parseSignedRequest(
          $_REQUEST['signed_request']);
      } else if (isset($_COOKIE[$this->getSignedRequestCookieName()])) {
        $this->signedRequest = $this->parseSignedRequest(
          $_COOKIE[$this->getSignedRequestCookieName()]);
      }
    }
    return $this->signedRequest;
  }

and the getSignedRequestCookieName() return

protected function getSignedRequestCookieName() {
    return 'fbsr_'.$this->getAppId();
   }

so now getSignedRequest() function first check whether signed request is set or not if not set it get signed request from Cookie

so if finally if you not want to get previous userid just delete cookie named ''fbsr_'+YourApplicationID'

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文