views:

1453

answers:

2

Hi all!

I am new to oauth and I'm trying to use facebook connect with my web-application.

I have succeded in getting a verification token but my problem is "fetching" the access token. How do I fetch it? Facebook documentation tells me to fetch the access token with this URL:

https://graph.facebook.com/oauth/access_token?'
                + 'client_id=XXXXXXXXXXXX& redirect_uri=http://www.mysite.com/fbconn/index.html&display=touch&'
                + 'client_secret=axxxxxcxxxxxxxxxxx&code=' + code;

When I use this I see the access token on a blank page, but I want to fetch it with javascript (AJAX) /PHP or something. Is this possible? I thought the access token would be appended to my redirect uri like the verfication code but I never get redirected to my page. What am I doing wrong?

Grateful for help/comments

/Chris

A: 

You need to add &type=user_agent to the request. You well get the AuthToken with a hash marker in the following format: http://yourredirecturi#code=[accesstoken].

If you set the request to &type=web_server, you'll get the AuthToken as a query string parameter: http://yourredirecturi&code=[accesstoken].

Here is a full explanation of how to implement the Facebook's OAuth protocol. The code samples are in ASP.NET MVC, but it should translate well enough to any language:

Full Explanation of the Facebook oAuth protocol: http://amirrajan.net/Blog/asp-mvc-and-facebook-single-sign-on

Amir
Thank you Amir, that helped!!
Chris Sunderland
A: 

$token = file_get_contents("the access token url"); will give u the access_token

rahul
u sir, is my saviour
p0larBoy