我是 OAuth 的新手,我正在尝试使用 Facebook Connect 与我的Web应用程序配合.
I am new to OAuth, and I'm trying to use Facebook Connect with my web-application.
我成功获取了验证令牌,但是我的问题是获取"访问令牌.我该如何获取? Facebook文档告诉我要使用以下URL来获取访问令牌:
I have succeded in getting a verification token, but my problem is "fetching" the access token. How do I fetch it? The Facebook documentation tells me to fetch the access token with this URL:
graph.facebook/oauth/access_token?' + 'client_id=XXXXXXXXXXXX& redirect_uri=www.mysite/fbconn/index.html&display=touch&' + 'client_secret=axxxxxcxxxxxxxxxxx&code=' + code;当我使用它时,我会在空白页上看到访问令牌,但是我想使用JavaScript(Ajax),PHP或其他东西来获取它.这可能吗?我以为访问令牌会像验证代码一样附加到我的重定向URI上,但是我从来没有重定向到我的页面.我在做什么错了?
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?
推荐答案您需要将&type=user_agent添加到请求中.您将以以下格式获得带有哈希标记的AuthToken.
You need to add &type=user_agent to the request. You will get the AuthToken with a hash marker in the following format.
yourredirecturi#code=[accesstoken]如果将请求设置为&type=web_server,则将获得AuthToken作为查询字符串参数:yourredirecturi&code=[accesstoken].
If you set the request to &type=web_server, you'll get the AuthToken as a query string parameter: yourredirecturi&code=[accesstoken].
这里是有关如何实现Facebook的OAuth协议的完整说明.这些代码示例在ASP.NET MVC中,但是它应该可以很好地转换为任何语言:
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:
Facebook平台的OAuth 2.0协议和ASP.NET MVC
更多推荐
使用Facebook OAuth 2.0
发布评论