我正在通过我的应用通过Facebook和Google+等社交网站进行身份验证。我选择了React.js进行查看。
这是我的代码:
这是我使用Login
React组件的代码。现在,我想尝试使用Facebook,Google +和Twiiter进行身份验证。
"api": { "twitter": { "consumerKey": "value", "consumerSecret": "value, "token": "value", "tokenSecret": "value" }, "facebook": { "clientId": "value", "clientSecret": "value", "callbackUrl": "url" }, "google": { "clientId": "value", "clientSecret": "value", "callbackUrl": "url" } }
请帮助我:如何在JSX代码中使用这些API?
经过大量工作后,我现在可以使用React.js登录Facebook。
<body> <button class="connect">Connect</button> <div class="target"></div> <div id="fb-root"></div> <script type="text/jsx"> /** * @jsx React.DOM */ var Profile = Backbone.Model.extend({ defaults : { name : null, gender : null, picture : null } }); var CardComponent = React.createClass({ componentWillMount : function() { profile.on("change", (function() { this.forceUpdate(); }.bind(this))); }, componentWillUnmount : function() { profile.off("change"); }, render : function() { return ( <div className="card"> <div className="picture"> <img src={this.props.profile.get("picture")} /> </div> <div className="name"> {this.props.profile.get("name")} <small> ({this.props.profile.get("gender")}) </small> </div> </div> ); } }); var connect = document.querySelector(".connect"); var target = document.querySelector(".target"); var profile = new Profile(); var fetchProfile = function() { React.renderComponent( <CardComponent profile={profile} />, target ); FB.api("/me", "get", {}, function(result) { profile.set("name", result.name); profile.set("gender", result.gender); }); var params = "?redirect=false&; FB.api("/me/picture" + params, "get", {}, function(result) { profile.set("picture", result.data.url); }); }; var login = function() { FB.login(function() { fetchProfile(); }); }; window.fbAsyncInit = function() { FB.init({ appId : "238316539647012", status : true, xfbml : true }); connect.addEventListener("click", function() { login(); }); FB.Event.subscribe("auth.authResponseChange", function(response) { if (response.status === "connected") { fetchProfile(); } }); }; (function(d, s, id){ var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/all.js"; fjs.parentNode.insertBefore(js, fjs); }(document, "script", "facebook-jssdk")); </script>
我在本教程中使用了ribs.js
我觉得对某人有用