This is the request Facebook calls back:
/facebook/promo/#access_token=162592277090170%7C2.yCch3otjrdit_rgBFS6F0A__.3600.1285369200-7开发者_如何学Go27781553%7CtugQmoO0bRiadumHVQrrSiPRD9Y&expires_in=7174
How can I parse the access_token
from the URL? I could not find any way to get the access_token
value.
Please be aware that it is not a reqular parameter.
You could use a Regex to match it out of the url. Or simply take everything as a sub-string between access_token=
and the next &
-character or the end of the url, which ever comes first.
I believe that it's not possible - the part after # is simply ignored. See this answer: Rails: Extracting the raw url from the request
If you're only after the access_token=...
section, just use some simple string matching:
url = '/facebook/promo/#access_token=162592277090170%7C2.yCch3otjrdit_rgBFS6F0A__.3600.1285369200-727781553%7CtugQmoO0bRiadumHVQrrSiPRD9Y&expires_in=7174'
url[/#access_token=(.+)&/, 1]
=> "162592277090170%7C2.yCch3otjrdit_rgBFS6F0A__.3600.1285369200-727781553%7CtugQmoO0bRiadumHVQrrSiPRD9Y"
That looks for #access_token=
and grabs everything up to &
.
精彩评论