5

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.com/#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.

2 Answers 2

6

Assuming 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];
Sign up to request clarification or add additional context in comments.

1 Comment

What if the value already contains "="? Like if it's base64 encoded and has some "=" at the end.
2

Just split with '=' on the returned key value pair

var token = obj.split('=')[1] ;

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.