问题描述
我开发了一个简单的API,允许我的Android / iPhone应用程序,我的服务器之间的通信。在我的应用程序,用户需要验证自己和他们这样做是使用登录/用下面的API调用密码凭据:
I have developed a simple API to allow communication between my Android/iPhone apps and my server. In my application, users need to authenticate themselves and they do it using login/password credentials with the following API call:
http://api.myapp.com/login?user=xxx&pass=pass
应用程序收到回报:
Application receives in return:
{ "api_token": "xxxx-xxxx-xxxx-xxxx" }
所以基本上我交换我的凭据对 api_token
。
我想补充的Facebook连接的支持。我已经成功地使用Facebook的SDK和接收到正确的的access_token
。
I would like to add Facebook connect support. I have successfully used the Facebook SDK and receives the correct access_token
.
不过,我需要实现一种机制来交换的access_token
与 api_token
However, I need to implement a mechanism to exchange access_token
with api_token
假设用户已经连他的账户与Facebook(他的网站用户面板上),这将是着手交流的最佳执行?
Assuming the user has already connected his account with Facebook (on his web user panel), what would be the best implementation to proceed to the exchange?
推荐答案
下面是如何我终于做到了。它的工作非常好一年多,从未有过任何问题。我们的想法是使用下面的API调用交换标记:
Here is how I finally did it. It's working very well for more than one year, never had any problem. The idea is to exchange tokens using the following API call:
http://api.myapp.com/login/facebook?access_token=<facebook_access_token>
服务器端,您验证的access_token
的有效性用一个简单的
wget -qO- https://graph.facebook.com/me?access_token=<facebook_access_token>
它发送回你一个JSON的所有用户信息,包括用户的Facebook ID。假设已经连他账户的Facebook用户,你可以查找在 USER_ID
并发送回一个 api_token
。
这篇关于Facebook Connect来对个人进行身份验证API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!