how to create an account api for my site
i want to create an api for my sites so that i allow ot开发者_Python百科her web developers to integrete my api for their user login and signup ..... how can i do that...
This is an extremely broad question, so here's a broad answer: You make a page that takes arguments and outputs the answer in an easily-parsed format (JSON, XML, etc.)
For example: http://example.com/api?action=list_users could return:
<user>
<userid>1</userid>
<username>foo</username>
</user>
Create a way for developers to query your server, like Michael said. A common technology for this is called SOAP and another (simpler) is called REST, but you can of course use other formats if you wish.
The most important thing is that you document the API so other developers knows exactly how it works. Write down every detail about the API: how it works, which methods it provides and which arguments are mandatory and optional. Ideally you also provide examples or even a fully functioning client implementation.
Maybe I'm misunderstanding the question, but integration of login systems sounds like OpenID to me. Why make your own protocol when you can build to a standard one?
I personally prefer to use an MVC Framework to create an API as the structure for me is just right!
By using a system like CI (CodeIgniter) you can create a library for authentication.
This being said with the MVC Model you can use like so
http://example.com/api/users/latest/
http://example.com/api/users/id/33/
http://example.com/api/users/id/33/
The within your library just build the authentication process so you can quickly check permissions for different entites.
Example in PHP and CI
users > latest
class Controller_users extend CI_Controller
{
public function latest($limit = 10)
{
if($this->library->authorized(API_AUTH_LATEST))
{
//show the data.
}
}
}
The authorized function will automatically read the headers / for the API Key etc and trigger error output.
This to me is a simple way for an API to be achieved cutting out a lot of crap from SOAP.
精彩评论