How to set Facebook Access (from server) in JavasScript SDK -
if using server side flow authenticate user , acquire access token, how can set access token in javascript sdk , use make calls client side?
once user has finished server side authentication flow user authorized app, need use fb.getloginstatus method:
fb.getloginstatus(function(response) { if (response.status === "connected") { console.log("authresponse: ", response.authresponse); fb.api("me", function(response2) { console.log("hey there " + response2.name); }); } else if (response.status === "not_authorized") { // user logged in facebook hasn't authorized app, should not happen if went through server side authentication } else { // user logged out of facebook, should not happen } } as can see can use js sdk query graph, there's no need token manually, in case still need it, authresponse should have following format:
authresponse: { accesstoken: "aaaaaaa", expiresin: "bbbbbb", signedrequest: "cccccc", userid: "dddddd" } edit
if user logged facebook , has allowed , interacted app yes getloginstatus should return valid access token.
there few cases in not case, 1 of them being token has expired.
as states in handling invalid , expired access tokens:
desktop web , mobile web apps implement authentication javascript sdk
calling fb.getloginstatus() or ensuring status: true set when call fb.init() means next time user lands on application , signed facebook, authresponse object passed result of calls contain fresh, valid access token.
in case, act of user using application implicitly generates new access token.
Comments
Post a Comment