I know this is probably extremely simple, but I can't seem to figure it out or find the answer I'm looking for. I'm using Instagram's API to allow user's to login and see their feed. This is done on the client side with Javascript. After authorizing my app, the browser sends back an access token in the url like so: www.example/#access_token=12345679
.
What's the simpest vanilla JS to get the raw number of the access token? I've tried location.hash
but that returns both the key and value like so: acess_token=123456789
Any help appreciated.
I know this is probably extremely simple, but I can't seem to figure it out or find the answer I'm looking for. I'm using Instagram's API to allow user's to login and see their feed. This is done on the client side with Javascript. After authorizing my app, the browser sends back an access token in the url like so: www.example./#access_token=12345679
.
What's the simpest vanilla JS to get the raw number of the access token? I've tried location.hash
but that returns both the key and value like so: acess_token=123456789
Any help appreciated.
Share Improve this question edited Dec 9, 2013 at 22:54 linstantnoodles 4,4001 gold badge24 silver badges24 bronze badges asked Dec 9, 2013 at 22:35 Sean ThompsonSean Thompson 9021 gold badge9 silver badges19 bronze badges2 Answers
Reset to default 6Assuming the hash pattern is consistent, you can get the access_token value with the following code:
var hash = window.location.hash;
var accessToken = hash.split('=')[1];
Just split with '=' on the returned key value pair
var token = obj.split('=')[1] ;