使用 REST 和 HttpClient 访问 Facebook API
我将使用 RESTful Web 服务和 HttpClient 访问 Facebook API REST 服务器。
我是 REST 和 Facebook API 的新手...
问题:
验证/授权
(1) 如果我有客户端应用程序发送的会话密钥,我如何验证和验证该密钥用户存在然后在服务器端查询他/她的好友?
我如何访问这些 Facebook RESTful 端点:
http://wiki.developers .facebook.com/index.php/Users.getInfo
和
http ://wiki.developers.facebook.com/index.php/Friends.getLists
通过 HTTP GET 请求访问 ?意思是,包含参数的完整 URL 是什么样的?
(2) 获取 API(我已在上面列出)的完整 RESTful URL 是什么样子?
发帖到朋友墙
(3) 验证/授权后,查询用户好友,如何(使用哪个API)发帖到朋友墙?
(4) 我是否需要附加到 Facebook RESTful 服务器 URL 的任何其他参数?
HTTP 客户端
(5) 我是否通过 HttpClient 在我的 Java 程序中包含对这些 Facebook API 的 RESTful Web 服务调用?
祝您编程愉快,感谢您花时间阅读本文...
I am going to use RESTful Web Services and HttpClient to access Facebook API REST Server.
Am somewhat of a newbie to REST and Facebook APIs...
Question(s):
Verification / Authorization
(1) If I have a session key sent by a client app, how do I verify and authenticate that the user exists and then query for his / her friends on the server side?
How can I be access these Facebook RESTful end points:
http://wiki.developers.facebook.com/index.php/Users.getInfo
and
http://wiki.developers.facebook.com/index.php/Friends.getLists
via a HTTP GET Request? Meaning, what does the full URL look like including parameters?
(2) What would the full RESTful URL look like to grab the APIs (which I have listed above)?
Posting to a Friend's Wall
(3) After verification / authorization, querying users friends, how (which API) would I use to a post to a Friend's Wall?
(4) Is there any additional parameters that I need to append to the Facebook RESTful Server's URL?
HTTP Client
(5) Do I include the RESTful web service calls to these Facebook APIs inside my Java program through HttpClient?
Happy programming and thank you for taking the time to read this...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我无法回答您所有的问题,但方法调用是通过
http://api.facebook.com/restserver.php
进行的,因此对users.getInfo
的调用看起来像这样http://api.facebook.com/restserver.php?method=users.getinfo
您还需要传入您的 api 密钥以及该方法所需的任何其他参数。但是,您不必自己进行 http 调用,而必须有一些 Java 库为您抽象出所有这些内容。
至于这是一种 REST API,有一个 Web 服务端点,其方法范围位于 URL 中,并且所有调用都是通过 HTTP GET 或 POST 进行的。
坦率地说,这是基于 HTTP 的 RPC,与 REST 相差甚远(没有双关语!)。 Facebook 应该更改他们的 API 文档,这完全是错误的。
I can't answer all your questions but the method calls are made via
http://api.facebook.com/restserver.php
so a call tousers.getInfo
looks like thishttp://api.facebook.com/restserver.php?method=users.getinfo
You also need to pass in your api key and any other parameters the method needs. But rather than make the http calls yourself there must be some Java library that abstracts all this away for you.
As for this being a REST API - there's one web service endpoint with method scoping in the URL and all calls are made via HTTP GET or POST.
Frankly, this is RPC over HTTP and about as far from REST as you can get (no pun intended!). Facebook should change their API documentation, it's just plain wrong.
在创建 URL 方面,我使用了这段代码,它似乎工作得很好...
确保您看到关键组件 - 事实上参数是按字母顺序排序的,并且整个内容都是使用 MD5 加密的,但是加密的字符串与 URL 字符串略有不同。
另请注意,API 密钥需要填写!
因此,要获取 User.getInfo 方法的 URL 并返回名字和姓氏,我会执行以下操作...
希望这有帮助:)
In terms of creating the URL, I've used this code which seems to work pretty well...
Make sure you see the critical components - the fact that the arguments are alphabetically sorted, and that the whole thing is encrypted using MD5, but the string that is encrypted is slightly different than the URL string.
Also note that the API keys need to be filled in!
So, to get the URL for the method User.getInfo and return the first and last names, I'd do the following...
Hope this helps :)