哪里可以找到Facebook cookie? [英] Where to find the Facebook cookie?

查看:286
本文介绍了哪里可以找到Facebook cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此有点新意,请耐心等待。
我已经通过Javascript SDK安装了使用Facebook登录按钮,该工作正常。
我还设置了PHP代码(facebook.php)
我可以通过javascript成功登录到Facebook但是无法通过php从会话中访问UID。
那么,我如何让php访问会话javascript集?
谢谢

I'm kinda new to this so bear with me. I've installed a "Login with Facebook" button via the Javascript SDK, which works fine. I've also set up the PHP code (facebook.php) I can login successfully to Facebook via javascript but then can't access the UID from the session via php. So, how can I get php to access the session javascript sets? thanks

编辑(从下方发布代码,以便更容易阅读)

(Posting code from below here so it'll be easier to read)

我可以通过控制台记录响应并查看它。

I can console log the response and see it.

FB.getLoginStatus(function(response) {
    console.log(response.session.uid);
});

刷新页面,并尝试访问通过php设置的会话,它出现null。

Refresh the page, and try to access the session that was set via php, it comes up null.

require_once(RELATIVE_PATH.'applibs/facebook.php');
$config = array('appId'=>Config::$fb_app_id, 'secret'=>Config::$fb_secret, 'cookie'=>true);
$fb = new Facebook($config);
$fb->getUser(); // this will equal null because the $fb object isnt finding the cookie supposedly set by javascript

* 在第358行的facebook.php

* Did some debugging in the facebook.php

进行了一些调试...
$ cookieName = $ this-> getSessionCookieName();

//重新调整fbs_myNumericAppId,好像有用..

if(isset($ _ COOKIE [$ cookieName])){

// FAILS!没有$ _COOKIE ['fbs_myNumericAppId']

on line 358... $cookieName = $this->getSessionCookieName();
// retuns fbs_myNumericAppId, seems like that worked..
if (isset($_COOKIE[$cookieName])) {
// FAILS! there is no $_COOKIE['fbs_myNumericAppId']

这似乎合乎逻辑,因为登录facebook.com怎么能知道我的应用ID是什么?

登录到facebook.com后我也注意到,在$ _COOKIE中没有与facebook相关的内容。
所以,为了通过facebook.com登录facebook,然后有一个网站通知登录,你必须在页面加载上运行FB.login。
然后你必须通过返回$ _COOKIE的javacript信息设置一个cookie,这样php就可以在其他地方找到它。

That seems logical as how could logging into facebook.com know what my app ID is?
I also noticed after logging into facebook.com, there's NOTHING facebook related in $_COOKIE. So, in order to log into facebook via facebook.com, then have a website notice that login, you have to run FB.login on a page load. Then you have to set a cookie via the javacript info returned into $_COOKIE so the php can pick it up anywhere else.

推荐答案

我碰巧有一个博文和一些之前的 answers 可能对您有用。作为参考点。

I happen to have a blog post and some previous answers that may be of use to you as reference points.

您是否在Facebook上将您的网站注册为应用程序?如果没有,你需要这样做。 Facebook设置的cookie允许您的网站访问用户的信息(一旦他们同意给您的应用程序访问权限),就会使用您的应用程序ID和秘密(一个您不能共享的长字母数字字符串,或者其他应用程序可以冒充您的用户设置一个加密值,该用户的ID和用户及您的应用程序所特有的身份验证令牌(代表他们为您提供的数据的权限)。

Have you registered your site on Facebook as an "application"? If not, you'll need to do that. The cookie which Facebook sets that allows your site to access a user's information (once they've agreed to give your "application" access) uses a combination of your application's ID and "secret" (a long alphanumeric string that you must not share, or other applications would be able to impersonate yours) to set an encrypted value with the user's ID and an authentication token unique to the user and your application (representing the permission they've given you to their data).

Cookie会随着任何其他Cookie的请求一起发布到您的网站。您将使用应用程序的秘密对其进行解密并提取用户的ID和身份验证令牌,然后您可以使用它通过Facebook的图形API访问数据。

The cookie is posted to your site alongside requests like any other cookie. You'd use your application's secret to decrypt it and extract the user's ID and authentication token, which you would then use to access data via Facebook's graph API.

这篇关于哪里可以找到Facebook cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆