Page 1 of 1

Facebook api access token not splitting/stripping correctly

Posted: Tue Mar 25, 2014 2:57 am
by Case

Following along the 'build an app with facebook api' tutorial but hit a snag that I (think) I've finally isolated down to the 'access_code' not getting completely stripped to its individual string.

Through the web, when sending the request i get:
access_token=CAADXGeIZBR3MBAPzuF6KOwrlGZBsYnaqK9ZA4TBvG1RelgPIMOtSUNSLAFXs2KmVJXj78oULyjYfWMZBtitvUQE68oLcuT2of3gYgnmJqnpiquB7Dw5Q71kBE9SGtqE36QIBXsEWmwZA3I0ZAZBffwnIAQBQsHbibyo3wP3B9ZBEoYRNNRNF2hnnLL422aeKy14ZD&expires=5175703

After getting run through the JavaScript (referenced below) from step 9 of "Adding a service instance to the page", I get:
CAADXGeIZBR3MBAPzuF6KOwrlGZBsYnaqK9ZA4TBvG1RelgPIMOtSUNSLAFXs2KmVJXj78oULyjYfWMZBtitvUQE68oLcuT2of3gYgnmJqnpiquB7Dw5Q71kBE9SGtqE36QIBXsEWmwZA3I0ZAZBffwnIAQBQsHbibyo3wP3B9ZBEoYRNNRNF2hnnLL422aeKy14ZD&expires

For some reason '&expires' is still appended and not getting stripped/split off. This is then throwing an error ("Malformed access token" "Code 190") when attempting to authenticate on 'get data'.

Here is the code I'm using from the tutorial that is supposed to strip all the extraneous stuff:

var vars = jqXHR.responseText.split("&");
var access_token = vars[0].split("=")[1];
access_token = access_token.replace(/&.+/, "");
localStorage.setItem('access_token', access_token);

Any idea what's not working?


Facebook api access token not splitting/stripping correctly

Posted: Tue Mar 25, 2014 3:45 am
by Illya Stepanov

Hi Case,

If you mean code in "get_token" complete event you should use following code:
pre
var access_token = /access_token\=([^&]+)/gi.exec(jqXHR.responseText)[1];

localStorage.setItem('access_token', access_token);
/pre


Facebook api access token not splitting/stripping correctly

Posted: Tue Mar 25, 2014 5:59 am
by Case

Thank you much Illya, that did the trick.
Probably would be good to revise the current tutorial to save others any confusion.

Much appreciated!