如何让我的欢迎文字出现? [英] How to make my welcome text appear?

查看:91
本文介绍了如何让我的欢迎文字出现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

登录后,我希望文本欢迎,尼克拉斯显示,但登录后,我必须重新加载页面,我不明白如何使页面显示服务器变量 current_user 中的文本。如果我登录并按重新加载,则出现正确的欢迎消息。你能帮我实现我想要的吗?为什么FB python + javascript没有简单的工作示例?我可以实现没有javascript的Facebook连接吗?如果是这样,我必须自己使用和设置cookie?谢谢

After login, I want the text "Welcome, Niklas" to display but after logging in I have to reload the page and I didn't understand how to make the page display the text from the server variable current_user. If I login and press reload then the correct welcome message appears. Can you help me achieve what I want? Why is there no simple working example for FB python + javascript? Can I implement facebook connect without javascript? If so, do I have to use and set the cookie myself? Thank you

{% load i18n %}
<!DOCTYPE html> 
<html xmlns:fb="https://www.facebook.com/2008/fbml">
  <head> 
    <title> 
      Test Facebook SDK
    </title> 
  </head> 
<body> 
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '164355773607006', // App ID
      channelURL : '//WWW.KOOLBUSINESS.COM/static/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      oauth      : true, // enable OAuth 2.0
      xfbml      : true  // parse XFBML
    });
  };
  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     d.getElementsByTagName('head')[0].appendChild(js);
   }(document));
</script>
<fb:login-button autologoutlink="true"></fb:login-button>
{% if current_user %}
<div id="user-ident">
<span>{% trans "Welcome," %} <b>{{ current_user.name|escape }}</b></span>
</div>
{% endif %}
</body> 
</html>

这是我如何获取变量 current_user / p>

Here's how I get the variable current_user

@property
def current_user(self):
    if not hasattr(self, "_current_user"):
        self._current_user = None
        cookie = facebook.get_user_from_cookie(
            self.request.cookies, facebookconf.FACEBOOK_APP_ID, facebookconf.FACEBOOK_APP_SECRET)
        logging.debug("logging cookie"+str(cookie))
        if cookie:
            # Store a local instance of the user data so we don't need
            # a round-trip to Facebook on every request
            user = FBUser.get_by_key_name(cookie["uid"])
            logging.debug("user "+str(user))
            logging.debug("username "+str(user.name))

            if not user:
                graph = facebook.GraphAPI(cookie["access_token"])
                profile = graph.get_object("me")
                user = FBUser(key_name=str(profile["id"]),
                            id=str(profile["id"]),
                            name=profile["name"],
                            profile_url=profile["link"],
                            access_token=cookie["access_token"])
                user.put()
            elif user.access_token != cookie["access_token"]:
                user.access_token = cookie["access_token"]
                user.put()
            self._current_user = user
    return self._current_user


推荐答案

使用Oauth 2.0

When using Oauth 2.0

FB.Init(...oauth=true) 

登录按钮将cookie设置为您的域名为



the login button is setting a cookie into your domain named

fbsr_(appid)=....

使用应用程式密钥进行编码,并且不再含有用户令牌

which is encoded using the app secret key, and which do not contain the user token anymore.

如果你真的想要av使用java脚本客户端(这是最简单的方法),您可以利用此cookie的存在来知道用户是否连接到Facebook,然后执行任何授权检查或动态显示欢迎消息。

If you really want to avoid the use of java script client side (which is the most simple way) you can leverage the presence of this cookie to know if the user is connected to facebook and then perform any authorization check or dynamically display a welcome message.

我不使用python,所以我没有工作的例子,但这给你一种搜索方式。

I do not use python, so i do not have working example, but this give you a way to search.

希望这个帮助。

这篇关于如何让我的欢迎文字出现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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