简体   繁体   English

从 URL 获取 Facebook access_token

[英]Get Facebook access_token from URL

I implemented a Facebook app with Java servlets.我用 Java servlets 实现了 Facebook 应用程序。 I wonder how I can read the access token from the HTTP request sent by Facebook after authentication.我想知道如何在身份验证后从 Facebook 发送的 HTTP 请求中读取访问令牌。

The request sent to me by Facebook looks like this: http://myserver/app/servlet#access_token=3108888%7C2.AQByEGAdEk7D5hs3.3600.130400.1-10005014%7C3XTVE&expires_in=4317由ZD85544FCE发送给我的请求402C7A2A96A48078078EDAF203Z看起来像: http://myserver/app/servlet#access_token=3108888%7C2.AQByEGAdEk7D5hs3.3600.130400.1-10005014%7C3XTVE&expires_in=4317

How can I read the access token (which is a fragment and not a parameter) in my Java servlet?如何在我的 Java servlet 中读取访问令牌(这是一个片段而不是参数)? If it was a parameter I would do:如果它是一个参数,我会这样做:

request.getParameter("access_token);

To make facebook send the request which contains access_token in http parameters, one needs to change the resoponse_type parameter in request.要让facebook发送http参数中包含access_token的请求,需要修改resoponse_type参数。 It is of two types code and token .它有两种类型codetoken If we pass token the access_code will be in url fragment and if we pass token it will be request parameter with key as code .如果我们传递token ,则access_code将在url 片段中,如果我们传递token ,它将是请求参数,键为code

See: Constructing a URL to the OAuth Dialog请参阅: 构建 URL 到 OAuth 对话框

For server side handling of access_code eg in some servlet, it is needed to send request_type as code else it can be handled only in client side through javascript.对于访问代码的服务器端处理,例如在某些 servlet 中,需要将request_type作为code发送,否则只能通过access_code在客户端处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM