问题
Since I'm developing a pure frontend app with no backend, I'm going with Instagram implicit authentication. The problem is, after the user authorizes the app, Instagram redirects to my redirect_uri with the access token like this, http://your-redirect-uri#access_token=ACCESS-TOKEN
. How do I extract the access token from this? I tried using the router but with '#' it was not successful
回答1:
Use window.location.hash
to access to all parameters starting from #.
Or you can use window.location.href
to access full URL.
To get the token you can use window.location.hash.match(/#access_token=([^&]+)/)[1]
.
Note: If you are using TypeScript then you'd need to import window in your component.
declare let window;
来源:https://stackoverflow.com/questions/50193610/extracting-access-token-from-instagram-redirect-with-angular-5implicit-authenti