Case
Posts: 0
Joined: Mon Mar 10, 2014 12:08 am

Facebook api access token not splitting/stripping correctly

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?

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Facebook api access token not splitting/stripping correctly

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

Case
Posts: 0
Joined: Mon Mar 10, 2014 12:08 am

Facebook api access token not splitting/stripping correctly

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

Much appreciated!

Return to “Issues”