如何建立一个社交网络如Twitter的API,Facebook的? [英] How to build an API for a social network like twitter, facebook?

查看:201
本文介绍了如何建立一个社交网络如Twitter的API,Facebook的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Android的发展有一定的了解,也做了一些应用程序使用REST,但知道我要发展我自己的API,我正在开发一个即是去工作,如Facebook,人们可以发布照片的社交网络,有要成为一个像按钮,他们可以发表评论,每个人都会有带有图片的轮廓,等等。

I have some knowledge of Android Development, have done some apps consuming restful, but know I want to develop my own API, I'm developing a social network that is going to work like Facebook, people can post photos, there is gonna be a like button and they can comment, each one will have a profile with pictures, etc.

但我不知道如何构建的API,我想用laravel的是,我找到了最实用,清洁的框架,但我需要如何构建的API,哪些地方应该怎么开始的指南?

But I don't know how to build the API, I want to use laravel for that, I found the most practical, clean framework, but I need a guide on how to build that API, what and where should I start?

推荐答案

有参与创造一个API许多细节,但这里是一些信息,让你开始。

There are many specifics involved in creating an API but here is some information to get you started.

如果您正计划暴露你的API,由第三方(而不仅仅是你的应用程序)可以使用,那么你将需要投入的身份验证方法到位。目前规范的(这脸谱,github上等使用)是OAUTH2。你可以阅读更多有关OAUTH2这里 https://tool​​s.ietf.org/html/rfc6749

If you are planning to expose your API to be used by third parties(and not just your app) then you will need to put in an authentication method in place. The current specification for that(which facebook, github etc use) is OAUTH2. You can read more about OAUTH2 here https://tools.ietf.org/html/rfc6749

至于在Laravel实现它, http://oauth2.thephpleague.com/ 是一个包让你开始,但你可以在google,发现多了很多。

As for implementing it in Laravel, http://oauth2.thephpleague.com/ is a package to get you started but you can google and find a lot more.

如果您打算只在内部使用的API您的应用程序,那么你可以实现一个更轻质的身份验证方法。

If you are planning to use the API internally only by your app then you can implement a much light weight authentication method.

在验证方法到位,它是通过JSON暴露你的数据库数据的所有问题。这很简单,查询数据库,并把结果作为JSON响应。认为这是一个正常的MVC的网站,只有响应不是模板HTML,它是JSON。

Once the authentication method is in place, it is all a matter of exposing your database data through JSON. This is as simple as querying your database and sending the results as JSON response. Think of this as a normal MVC website, only that the response is not templated HTML, it's JSON.

此外,就像你的网站的某些领域需要身份验证,所以你做一个检查,如果用户登录,在这种情况下,这将是照顾了OAUTH2框架,使所有请求您的API进行身份验证。

Also, just like some areas of your website require authentication so you make a check if the user is logged in, in this case, this will be taken care of by the OAUTH2 framework so that all requests to your API are authenticated.

至于架构,服务器对OAUTH2,API和该数据库将分开。您也可以实现负载均衡,如果你期待在您的API一个高流量。

As for the architecture, the servers for OAUTH2, API and the database will be separate. You can also implement load-balancing if you are expecting a high traffic on your API.

这篇关于如何建立一个社交网络如Twitter的API,Facebook的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆