使用Facebook OAuth 2.0

编程入门 行业动态 更新时间:2024-10-24 06:35:44
本文介绍了使用Facebook OAuth 2.0-如何获取访问令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是 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

本文发布于:2023-11-14 09:14:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586815.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Facebook   OAuth

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!