Skip to main content
spradhan
Inspiring
October 28, 2013
Question

Parsing over pound sign in facebook connect URL

  • October 28, 2013
  • 1 reply
  • 2094 views

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://mydomain.com/mypage.cfm&scope=read_stream,offline_access

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?

    This topic has been closed for replies.

    1 reply

    Inspiring
    October 28, 2013

    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.

    spradhan
    spradhanAuthor
    Inspiring
    October 28, 2013

    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

    Inspiring
    October 28, 2013

    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.