用于OAuth身份验证的Facebook代码参数

时间:2011-12-14 19:06:43

标签: java facebook oauth token

我构建了一个FB应用程序,它执行以下操作:

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中,获取“code”参数(这是signed_request?):

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

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

//此参数在实际“代码”的末尾包含“#strong> _ = _ ”,但我无法得到它     通过request.getParameter(“code”);这是一个java web应用程序。

  

1 个答案:

答案 0 :(得分:3)

Facebook API's OAuth Page

复制

With this code in hand, you can proceed to the next step, app authentication, to gain the access token you need to make API calls. In order to authenticate your app, you must pass the authorization code and your app secret to the Graph API token endpoint - along with the exact same redirect_uri used above - at https://graph.facebook.com/oauth/access_token. The app secret is available from the Developer App and should not be shared with anyone or embedded in any code that you will distribute (you should use the client-side flow for these scenarios).

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

If your app is successfully authenticated and the authorization code from the user is valid, the authorization server will return the access token.

所以是的,这是OAuth的标准。获取成功代码,将其打入上面的URL(使用相应的client_id,client_secret和redirect_uri),您应该是现金。你将获得一个访问令牌,并从那里获得派对时间。

阅读Facebook API文章。它非常有用。如果您对此有疑问,我很乐意为您提供帮助。

祝你好运:)