2011-06-04 54 views
0

我建立一个FB的应用程序,其执行以下操作:获得从代码参数的Facebook OAuth凭证

1)重定向初始请求到FB,为了认证/登录,如下:

https://www.facebook.com/dialog/oauth?client_id=MYAPPID&redirect_uri=http://localhost:8080/FB/servlet&scope=read_stream&response_type=code

2)在servlet中,获得了 “代码” 参数(这是signed_request):

String signedReq = request.getParameter("code"); 

// the String retrieved from the code parameter is: 
// 3DaDJXq1Mlsq67GbeudlUxu7bY5Um4hSJlwzoPCHhp4.eyJpdiI6Ikc1ODNuRjZXbnhCb0hUV1FEMVNTQUEifQ._iXKxSGiNHfc-i5fRO35ny6hZ03DcLwu4bpAkslqoZk6OfxW5Uo36HwhUH2Gwm2byPh5rVp2kKCNS6EoPEZJzsqdhZ_MhuUD8WGky1dx5J-qNOUqQK9uNM4HG4ziSgFaAV8mzMGeUeRo8KSL0tcKuq 

3)如何从这个字符串OAuth令牌?

在此先感谢! 中号

+0

http://stackoverflow.com/questions/7510622/validate-and-get-data-from-facebook-cookie-using-oauth-2-0 在那里,你得到了答案。 – 2011-09-26 13:04:18

回答

4

在它告诉你它发回给Facebook facebook的文档:

http://developers.facebook.com/docs/authentication/

基本上你这样:

https://graph.facebook.com/oauth/access_token? 
    client_id=YOUR_APP_ID&redirect_uri=YOUR_URL& 
    client_secret=YOUR_APP_SECRET&code=THE_CODE_FROM_ABOVE 

这应该为你工作一般。