简体   繁体   English

如何从Facebook画布身份验证中获得最佳性能

[英]How to get the best performance from facebook canvas authentication

Facebook document that you need to do the following for canvas login 您需要执行以下操作以进行画布登录的Facebook文档

  1. Include facebook library 包括Facebook图书馆
  2. Instantiate class with App Id and secret 使用应用ID和密码实例化课程
  3. Check that the user has a valid session 检查用户是否具有有效的会话

    If they do check also that you can get there user object by doing an api call /me 如果他们也检查您是否可以通过执行api调用/ me到达用户对象

    If they dont then process the login redirect 如果他们不这样做,则处理登录重定向

All this especially the Facebook calls can take quite some time to process 所有这些,尤其是Facebook调用,可能需要花费一些时间来处理

The example shows this in terms of code http://github.com/facebook/php-sdk/blob/master/examples/example.php 该示例通过代码http://github.com/facebook/php-sdk/blob/master/examples/example.php展示了这一点

And from what I read it seems required on every page. 从我阅读的内容来看,似乎每一页都需要。 Because a user can logout / remove app / change permissions etc during the session 因为用户可以在会话期间注销/删除应用程序/更改权限等

My question is what is the ideal way of doing the above in terms of performance gains, but still making sure that it conforms to the nuiances of facebook. 我的问题是,从性能方面来讲,实现上述目标的理想方法是什么,但仍要确保它符合facebook的要求。

Facebook do give a session expire time which seems to be in GMT. Facebook确实提供了会话过期时间,这似乎是格林尼治标准时间。

I code in PHP using the Zend Framework but I suppose the above relates to all languages. 我使用Zend Framework在PHP中进行编码,但我想以上内容与所有语言都有关。

Appreciate your help on this 感谢您的帮助

Ian, store your user facebook credentials in the user related table (or whatever) Ian,将您的用户Facebook凭据存储在用户相关表(或其他任何表)中

facebook_user_id facebook_secret facebook_token facebook_user_id facebook_secret facebook_token

make it come out like something like: 使它像这样出来:

$user->facebook_session_array();

Then just pass that into your api class when you want to reuse it. 然后,当您想重用它时,只需将其传递给您的api类即可。 There is nothing you can do to make the oauth process (on authentication) go any faster because it has to happen live. 您无法采取任何措施使oauth流程(在身份验证时)更快地进行,因为它必须实时进行。

Cache the living daylights out of anything and everything you bring back from facebook.. run some crons in the background to either insert that stuff to table or stamp it down on a drive. 将您从Facebook带回来的任何事物和所有事物都缓存起来。.在后台运行某些控件,以将其插入表中或将其标记在驱动器上。 Your cron script should be able to handle potential rate limitations. 您的cron脚本应该能够处理潜在的速率限制。 I wrote some, but facebook is so slow, I think it was pointless. 我写了一些,但是facebook太慢了,我认为那毫无意义。

Facebook is slow.. don't make your app wait for it in any way you can avoid it. Facebook的速度很慢..不要让您的应用以任何可以避免的方式等待它。

first of all you'll have to authorize a user via facebook api, if you like to work with data of this user. 首先,如果您想使用该用户的数据,则必须通过facebook api授权该用户。 As a result of a successful authentication your application will receive an access_token and a expire_time. 认证成功的结果是您的应用程序将收到一个access_token和expire_time。 The value of expire time is expressed in seconds, not a timestamp in GMT. 到期时间的值以秒表示,而不是GMT中的时间戳。

Your application has the permission, to store the access_token and expire_time within it's own session handling, eg You'll need the access_token to make requests on behalf of the user to the facebook api. 您的应用程序具有在自己的会话处理中存储access_token和expire_time的权限,例如,您将需要access_token代表用户向facebook api发出请求。 With the expire_time value (and the time you authorized the user) you can check the validity of your access_token before calling fb API methods... and in case it expired, you should reauthenticate. 使用expire_time值(以及您授权用户的时间),您可以在调用fb API方法之前检查access_token的有效性...并且万一它过期了,您应该重新进行身份验证。

You definitly do NOT need to reauthenticate on every page reload of that user. 您不必在每次重新加载该用户时都重新进行身份验证。

If the user changes something on facebook (eg, removes your application) then a call to the api might fail with an "OAuthException" error. 如果用户更改了facebook上的某些内容(例如,删除了您的应用程序),则对api的调用可能会失败,并显示“ OAuthException”错误。 Your application should be aware of such errors and handle them appropriate. 您的应用程序应注意此类错误,并进行适当处理。

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

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