• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Parsing over pound sign in facebook connect URL

Explorer ,
Oct 28, 2013 Oct 28, 2013

Copy link to clipboard

Copied

I am trying to create a facebook connect page and am getting stuck at a seemingly triffle issue because I cannot parse correctly.

I send my information to Facebook for authentication

https://graph.facebook.com/oauth/authorize?type=user_agent&client_id=xxxxxxx&redirect_uri=http://myd...

Facebook authenticates the user and sends back the access_token which is needed for all calls thereafter to the redirect_uri page in the following form

http://mydomain.com/mypage.cfm#access_token=xxxxxxxxxxxxxxxxxxxxxxx

Now, I need to get the access_token so I can make the subsequent calls, but I am not able to extract the value of the access_token using coldfusion. It seems like a very easy thing but I am stuck at this point. If it was of the usual "?access_token=xxxx" form then it would have been a piece of cake but the pound sign is preventing me from parsing it.

Anyone have any idea?

Views

1.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 28, 2013 Oct 28, 2013

Copy link to clipboard

Copied

I have not messed with Facebook integration (though I am being tasked with that shortly)  However, if you simply need the value of access_token from that URL, and you are SURE that no '#' can exist in the value of access_token, you can use (assuming myStr = the full URL you listed: http://mydomain.com/mypage.cfm#access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)

<cfset access_token = listLast( listLast( myStr, '##' ), '=' ) />

This basically says "Find all the # in the value, and send me the value beyond the last one (saw it as a character separated list, where '#' is the separator.

And then take THAT value (which should be 'access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') and do the same thing, except use '=' as the delimeter, so it should return the xxxxxxxxxxxxxxxxxxxxxxx value.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 28, 2013 Oct 28, 2013

Copy link to clipboard

Copied

I would have liked to do that except for the fact that I haven't found a way to create the "myStr" variable which would contain the full URL. How do you propose I get the full URL including everything after the pound sign?

What happens is facebook redirects to that page ie http://mydomain.com/mypage.cfm#access_token=xxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxx

So "mypage.cfm" needs to parse out the access_token

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 28, 2013 Oct 28, 2013

Copy link to clipboard

Copied

Goto your mypage.cfm and put in a:

<cfdump var="#CGI#" />

Then navigate out to your mypage.cfm and put a '#access_token=xxxxxxxxxxxxxxxxxxxxxxxxxx' onto it and see if any variable in the CGI scope maintains that value.  (Check 'script_name' in particular)  Let me know if any variable maintains that information; it will be the one you'll want to use for parsing.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 28, 2013 Oct 28, 2013

Copy link to clipboard

Copied

Did that already, but nothing contained the elusive "#access_token=xxxxxxxxxx" Just feels like it should be something easy to get to...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 28, 2013 Oct 28, 2013

Copy link to clipboard

Copied

It looks like CF strips off hash parameters from the CGI variables.  You might be able to access the full URL with the hash parameter via GetHTTPRequestData(), though.

-Carl V.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 28, 2013 Oct 28, 2013

Copy link to clipboard

Copied

Nevermind, GetHTTPRequestData() doesn't do it.  I also tried noodling around with GetPageContext(), but couldn't find anything useful there either.  This StackOverflow post might provide some insight.

-Carl

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 28, 2013 Oct 28, 2013

Copy link to clipboard

Copied

GetPageContext() did not help. Seems like I've hit a brick wall

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 28, 2013 Oct 28, 2013

Copy link to clipboard

Copied

It seems from that SO post that anything following a pound sign in a URL is by design intentially ignored server side, as it is intended to be used client-side by JavaScript.  Not sure what to do about that...

-Carl V.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 28, 2013 Oct 28, 2013

Copy link to clipboard

Copied

I've been reading up and it seems that the anchor stub on a URL is actually not sent to the server.  It is a behavior function of the browser.  Browsers check for it, and if they find an ID in the page, they simply move the scrollbar to that point.

That being said, if this is how Facebook sends back the token, I'm assuming they want your page to capture it (our current problem) and then to either store it in a persistent scope for the remainder of the visit, right?  Have you looked into how other languages handle this?  I can't fathom why FB would request a URL with an anchor stub rather than a query string.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 28, 2013 Oct 28, 2013

Copy link to clipboard

Copied

Thanks everyone for trying to help out. If I was able to extract the access_token this way, it would have been a easy way to work on facebook connect. There are other more complicated ways to do it. I suppose I will have to look into those. Thanks and I really appreciate all your pointers.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 29, 2013 Oct 29, 2013

Copy link to clipboard

Copied

LATEST

The https://developers.facebook.com/docs/facebook-login/access-tokens/ documentation shows a couple of Open Graph URLs to just get the access token. Did you try doing a CFHTTP to:

https://graph.facebook.com/oauth/access_token?client_id={app-id}&client_secret={app-secret}&grant_ty...

You'd have to hard-code the client_secret, or perhaps take it from a database, but it may yield the elusive token.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation