javascript - Rails / Facebook SDK - Storing user access token into Rails object -
i'm working on app i'm using facebook javascript sdk allow users login give access manage pages. i'm getting stuck pretty on trying figure out how can store user's user access token after login, , retrieve when want grab other elements later. far have working -
application.js-
window.fbasyncinit = function() { fb.init({ appid : 'my-app-id', autologappevents : true, xfbml : true, version : 'v2.10' }); }; (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/sdk.js"; fjs.parentnode.insertbefore(js, fjs); }(document, 'script', 'facebook-jssdk'));
profile.html.erb -
<script> (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/sdk.js#xfbml=1&version=v2.10&appid=my-app-id"; fjs.parentnode.insertbefore(js, fjs); }(document, 'script', 'facebook-jssdk')); </script> <div class="fb-login-button" data-scope="public_profile,email,manage_pages,publish_pages,pages_show_list" data-max-rows="1" data-size="large" data-button-type="login_with" data-show-faces="false" data-auto-logout-link="true" data-use-continue-as="false"> </div> </div>
once user logs in using above code, want make call api page access token , store under user account. know things working point, because can run following javascript on button click , correctly gets token -
fb.getloginstatus(function(response) { if (response.status === 'connected') { var fbusertoken = response.authresponse.accesstoken; console.log(fbusertoken); }else{ //error not connected } });
i tried looking @ koala gem, it's returning nil when try user access token cookies.
does have pointers or examples has been implemented can at? there data api store in rails objects, prefer of work there if possible.
Comments
Post a Comment