简体   繁体   English

Facebook离线访问密钥和登录

[英]Facebook Offline Access Key and login

I've been working on this for a while now and I can't seem to get it to work. 我已经在这方面工作了一段时间,我似乎无法让它工作。 It seems to be a frequently asked, but a rarely well-answered question. 这似乎是一个经常被问到但很少回答的问题。

I want my website's users to link their facebook account with my website. 我希望我的网站的用户将他们的Facebook帐户与我的网站链接。 So they can see their stream etc on my site. 所以他们可以在我的网站上看到他们的流等。

At the moment, each time they log into my site they have to connect with facebook again. 目前,每次他们登录我的网站时,他们都必须再次与Facebook联系。 I want to have the option for users to give me offline_access to their data, so they don't have to re-login to facebook/re-connect with my site each time they come to my site. 我希望用户可以选择将offline_access提供给他们的数据,这样他们每次访问我的网站时都不必重新登录Facebook /重新连接我的网站。 As its kind of the point of my site in general. 作为我的网站的一般点。

To do this I understand I need to get offline access. 为此,我了解到我需要离线访问。 ( https://developers.facebook.com/docs/authentication/ ) Though from my searching it seems to be a bit light on documentation ( Facebook offline access step-by-step ). https://developers.facebook.com/docs/authentication/ )虽然从我的搜索中看起来似乎有点文档( Facebook离线访问一步一步 )。

I already know how to ask for offline access I'm just unsure of how to get the data from it. 我已经知道如何要求离线访问我只是不确定如何从中获取数据。

So my questions are as follows; 所以我的问题如下;

  1. How do I get the new infinate Session key after I request it? 我请求后如何获得新的infinate Session密钥?
  2. Once I have it and store it in the database - How do I create a facebook user with it instead of just going through the normal limited access key? 一旦我拥有它并将其存储在数据库中 - 如何使用它创建一个facebook用户而不是仅仅通过正常的受限访问密钥?

Just for further info. 仅供参考。 I'm using PHP ( codeigniter ) with Eliot Haughin's Facebook connect library Though if you can give me code using the regular php library I'll just convert it 我正在使用PHP( codeigniter )和Eliot Haughin的Facebook连接库虽然如果你可以使用常规的php库给我代码我只会转换它

Thanks very much 非常感谢

Right. 对。 After some more searching and poking around the code. 经过一些搜索和探索代码之后。 I figured it out. 我想到了。

I've tested it out for multiple users and over the course of a week and it works like a charm. 我已经为多个用户测试了它,并且在一周的时间里它就像一个魅力。

When you have gotten the offline_access permission, store the session key, and the user ID. 获得offline_access权限后,存储会话密钥和用户ID。 (wherever you want. I store mine in my database). (无论你想要什么。我将我的数据存储在我的数据库中)。

The infinite session key will look something like this df4175330aaddb9d50fd8f84-30000799 with everything after the 'dash' being the users ID. 无限会话密钥看起来像这样df4175330aaddb9d50fd8f84-30000799,其中包含“破折号”作为用户ID之后的所有内容。

Then the next time you call the API add this line of code in. 然后,下次调用API时,请添加以下代码行。

$this->fb->set_user('Facebook User ID', 'Offline Access Session key', 0); $ this-> fb-> set_user('Facebook用户ID','离线访问会话密钥',0); NB the zero is the amount of time before it will expire. 注意,零是它到期之前的时间量。 0 = never. 0 =从不。

My code in my library is as follows 我的库中的代码如下

$this->fb = new Facebook($this->_api_key, $this->_secret_key);     
//Query Database to see if user had enabled offline access.
//If So extract the userid and session key
$this->fb->set_user($fbuserid, $fbsess, 0);

In my testing this has worked perfectly. 在我的测试中,这非常有效。 Now my users can log into my site and have facebook automatically, once they give the offline_access permission. 现在,我的用户可以登录我的网站,并在获得offline_access权限后自动拥有Facebook。 Its currently been working for a week without problems. 它目前已经工作了一个星期没有问题。

I think thats everything. 我认为这就是一切。 But if I left anything out let me know. 但如果我遗漏了任何东西,请告诉我。

I've been working with facebook connect since they announced it at F8 and put it into beta a year ago, I'm in charge of the backend side of our Facebook connect integration on several large websites, and I've spent quite a bit of time on this issue specifically. 我一直在使用facebook connect,因为他们在F8上宣布它并在一年前进入测试版,我负责几个大型网站上我们的Facebook连接集成的后端,我花了不少钱特别是在这个问题上的时间。

Here's a good post on the topic , ande here's a bug filed 3 months ago . 这是关于这个主题的好帖子 ,这里是3个月前提交一个错误

Long story short, facebook is not actively supporting this type of session promotion -- yes, it's in the docs -- but it doesn't work. 长话短说,Facebook并没有积极支持这种类型的会话促销 - 是的,它在文档中 - 但它不起作用。 It's clearly not something they're actually testing internally. 这显然不是他们实际在内部测试的东西。

And from experience, let me tell you: if it's not a well documented, commonly used feature, you can't rely on facebook to maintain it. 根据经验,让我告诉你:如果它不是一个记录良好,常用的功能,你不能依靠Facebook来维护它。

The key expires every time a user changes their password. 每次用户更改密码时密钥都会过期。 This is written on the documentation. 这是写在文档上的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM