+ Start a Discussion
SaranshSaransh 

Unable to fetch token from Parameter

User-added image
I am not able to get access_token from above URL.

I have tried below code but even then 'token' is returning null value.
token = ApexPages.currentPage().getParameters().get('%23access_token');

 
Best Answer chosen by Saransh
Sergey TrusovSergey Trusov

Following code should works:

String token = ApexPages.currentPage().getAnchor();

All Answers

Sagar PareekSagar Pareek
Hi Saransh,

Do is it possible for you to remove # from the URL and use 
 
token = ApexPages.currentPage().getParameters().get('access_token');

 
Dushyant SonwarDushyant Sonwar
Hi Saransh,
You can do apex function to get Full url and then split it up '#' using string function 
Or
You can also use javascript function document.URL to get full Url and then split it where you find '#'.
Hope this helps you..
SaranshSaransh

I have tried doing everything but I am not getting any value.

@Dushyant Sonwar - I did tried apex function ApexPages.currentPage().getUrl(). but this one giving me correct URL till '?' and after that debug=1. No other extra parameter value. Javascript also is not returning complete URL. You can give this a try by making a demo page and append parameter manually to your URL using '#' in front and then you would going to face the same thing.

@Sagar Pareek - I can't remove '#' because this token I am getting during facebook integration. So, facebook is returning it.
 
Dushyant SonwarDushyant Sonwar
Hey Saransh,
document.URL.split('#')[1].split('=')[1]
i used this and it is giving me the parameter value.
 
Sergey TrusovSergey Trusov
Because it is not a parameter, it is a anchor.
Sergey TrusovSergey Trusov

Following code should works:

String token = ApexPages.currentPage().getAnchor();
This was selected as the best answer