简体   繁体   English

Facebook内容在服务器端获取

[英]Facebook content fetching on server-side

My goal is to develop iPhone application that can be used to view content that is partially composed from data (statuses, photos, videos) from Facebook friends of the phone owner. 我的目标是开发iPhone应用程序,该应用程序可用于查看部分由来自电话所有者的Facebook好友的数据(状态,照片,视频)组成的内容。

In other words the iPhone app should interact with some backend server that generates content and this backend should fetch data from facebook. 换句话说,iPhone应用程序应该与生成内容的一些后端服务器交互,这个后端应该从Facebook获取数据。 Currently I am thinking about using Django for backend. 目前我正在考虑将Django用于后端。

I haven't used any social api before, and I have a gut feeling that auth in this scheme may cause some problems, mostly because I have user, that should enter login/pass on the device-side and actual content fetching (from user's fb friends), on server-side. 我之前没有使用任何社交api,我有一种直觉,认为这个方案中的auth可能会导致一些问题,主要是因为我有用户,应该在设备端输入登录/传递和实际内容提取(来自用户的fb啦),服务器端。

What can help me to implement such scheme? 有什么可以帮助我实施这样的计划? Does fb api provides something like this at all? fb api会提供这样的东西吗?

Note that this is not a web project, I have native iPhone app. 请注意,这不是一个Web项目,我有原生的iPhone应用程序。

This is entirely feasible, it's just that it depends on you implementing the auth structure with an understanding that all the actions to grant permission for the app on facebook are going to need perform redirects. 这是完全可行的,它只是依赖于您实现auth结构,并理解为Facebook上的应用程序授予权限的所有操作都需要执行重定向。 This may involve opening a browser outside your app, or you can use the IPhone SDK just for the auth and have the access_token sent to your server by the client device after the OAuth process is completed. 这可能涉及在您的应用程序外打开浏览器,或者您可以仅使用IPhone SDK进行身份验证,并在OAuth流程完成后由客户端设备将access_token发送到您的服务器。

This is a very common approach for applications that want to setup their own auth system alongside Facebook/Twitter/Google + other OAuth providers. 对于想要与Facebook / Twitter / Google +其他OAuth提供商一起设置自己的身份验证系统的应用程序,这是一种非常常见的方法。 You maintain native user ids that are associated with some Facebook user and obtain the access token where necessary. 您维护与某些Facebook用户关联的本机用户ID,并在必要时获取访问令牌。 The process for obtaining permanent, offline access has changed from persistent tokens over to ones you refresh. 获取永久脱机访问的过程已从持久令牌更改为您刷新的令牌。 I'll reference you to another discussion that has all the pertinent details for that: 我将引用您的另一个讨论,其中包含所有相关细节:

What field type to store the facebook token? 用于存储facebook令牌的字段类型是什么?

Once a valid access_token is obtained and saved, either in a persistent storage or in the session, you can use it to access the same endpoints that the client side SDKs use to fetch and exchange data. 一旦获得并保存了有效的access_token,无论是在持久存储中还是在会话中,您都可以使用它来访问客户端SDK用于获取和交换数据的相同端点。 This is usually accomplished with some HTTP library. 这通常通过一些HTTP库来完成。 The SDK for PHP, for example, merely expedites this process from within a browser window by automating the auth process and then embedding the access credentials in request data for you. 例如,SDK for PHP仅通过自动执行身份验证过程,然后在您的请求数据中嵌入访问凭据,从浏览器窗口加快此过程。 This can totally be simulated on the server side by using the endpts with a standard HTTP lib (urllib or HTTPlib in python) and manually setting the newly obtained access_token as a request variable to be sent along to the graph API. 这可以通过使用具有标准HTTP库(python中的urllib或HTTPlib)的endpts并且手动将新获得的access_token设置为要发送到图API的请求变量来完全在服务器端模拟。

If you're going the python route and your needs on the client side are going to be entirely handled via the phone, I would highly suggest you look at Flask , which is a variant of the Werkzeug WSGI library. 如果您正在使用python路线并且客户端的需求将通过电话完全处理,我强烈建议您查看Flask ,它是Werkzeug WSGI库的变体。 This tool really can't be beat for spinning up quick endpts that echo out some serialized data (in your case, most likely JSON directly from FB). 这个工具真的不能用于旋转快速的结束,这些结束回显了一些序列化的数据(在你的情况下,很可能直接来自FB的JSON)。 I've always liked it for web services type work since it leave you open to decide what libraries to use for your other needs and thereby keeps the deployed codebase as small as possible. 我一直喜欢它用于Web服务类型工作,因为它让您可以决定使用哪些库来满足您的其他需求,从而使部署的代码库尽可能小。

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

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