digecon/elgg_web_services

elgg的Web服务插件

安装: 8

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

公开问题: 0

类型:elgg-plugin

dev-master 2015-01-27 13:32 UTC

This package is not auto-updated.

Last update: 2024-09-14 16:39:49 UTC


README

原始代码: github.com/Tachyon/Elgg-Web-Services

Elgg Web Services

Elgg是一个获奖的社交网络引擎,提供构建块,使企业、学校、大学和协会能够创建自己的完全功能的社交网络和应用。该Web服务插件可以安装到任何Elgg服务器上,并将在该服务器上启用Web服务。这些Web服务可以用来访问该Elgg服务器的数据,并允许开发者以新的和创造性的方式构建和扩展他们的应用。

简介

Elgg Web服务本质上是RPC Web服务,输出可以请求为JSON以及XML。这些Web服务基于Elgg的Web服务API。

调用Web服务

可以通过调用以下URL来对Web服务进行任何调用

```
<site URL>/services/api/rest/<outpput type>/?method=<method name>
```

这里:Elgg网站根目录的路径:json或xml:您想调用的远程方法名称

其他参数根据请求的Web服务类型,通过GET或POST传递。每个Web服务的请求类型已在本文档的后续部分定义

入门指南

安装

要在任何Elgg安装中使用这些Web服务,只需安装此插件。之后,为所有使用它们的程序生成API密钥对。此API密钥将需要在每个Web服务请求中以变量'api_key'的形式传递。

配置

所有Web服务分为七个大类别

* Core
* User
* Group
* Wire
* Blog
* File
* Like

根据需要启用或禁用这些Web服务。可以从“Web服务”在管理员设置中禁用或启用任何Web服务。

身份验证

Web服务使用Elgg的API身份验证Web服务进行身份验证。

身份验证的示例代码如下

```
$params = array(
	'username' => $username,
	'password' => $password,
);
$token = $this->post('auth.gettoken', $params);
```

此令牌将用于未来的所有Web服务调用。此令牌必须在每次调用中作为'auth_token'传递。

客户端类

源代码的“Class”文件夹中包含一个PHP类,该类可用于客户端软件。在“app/”文件夹中还有一个JavaScript客户端的早期示例。

Web服务列表

核心

  • site.test - 心跳方法以测试Web服务是否正常运行

    $info = $client->get('site.test');
    var_dump($info);
    
    object(stdClass)
    	public 'success' => boolean true
    	public 'message' => string 'Hello' (length=5)
    
  • site.get_info - 获取有关此Elgg站点的基本信息

    $info = $client->get('site.getinfo');
    var_dump($info);
    
    object(stdClass)[135]
    	public 'url' => string 'http://elgg-master.mbp/Users/brett/Devel/elgg/master' (length=52)
    	public 'sitename' => string 'New Elgg site' (length=13)
    	public 'language' => string 'en' (length=2)
    

用户

  • user.get_profile_fields - 获取个人资料字段

    $info = $client->get('user.get_profile_fields');
    var_dump($info);
    
    object(stdClass)[3]
      public 'description' => 
    	object(stdClass)[13]
    	  public 'label' => string 'About me' (length=8)
    	  public 'type' => string 'longtext' (length=8)
      public 'briefdescription' => 
    	object(stdClass)[12]
    	  public 'label' => string 'Brief description' (length=17)
    	  public 'type' => string 'text' (length=4)
      public 'location' => 
    	object(stdClass)[11]
    	  public 'label' => string 'Location' (length=8)
    	  public 'type' => string 'location' (length=8)
      public 'interests' => 
    	object(stdClass)[10]
    	  public 'label' => string 'Interests' (length=9)
    	  public 'type' => string 'tags' (length=4)
      public 'skills' => 
    	object(stdClass)[9]
    	  public 'label' => string 'Skills' (length=6)
    	  public 'type' => string 'tags' (length=4)
      public 'contactemail' => 
    	object(stdClass)[8]
    	  public 'label' => string 'Contact email' (length=13)
    	  public 'type' => string 'email' (length=5)
      public 'phone' => 
    	object(stdClass)[7]
    	  public 'label' => string 'Telephone' (length=9)
    	  public 'type' => string 'text' (length=4)
      public 'mobile' => 
    	object(stdClass)[6]
    	  public 'label' => string 'Mobile phone' (length=12)
    	  public 'type' => string 'text' (length=4)
      public 'website' => 
    	object(stdClass)[5]
    	  public 'label' => string 'Website' (length=7)
    	  public 'type' => string 'url' (length=3)
      public 'twitter' => 
    	object(stdClass)[4]
    	  public 'label' => string 'Twitter username' (length=16)
    	  public 'type' => string 'text' (length=4)
    
  • user.get_profile - 获取个人资料信息

    $params = array("username" => "admin");
    $info = $client->get('user.get_profile', $params);
    var_dump($info);
    
    object(stdClass)[3]
      public 'description' => null
      public 'briefdescription' => null
      public 'location' => null
      public 'interests' => null
      public 'skills' => null
      public 'contactemail' => null
      public 'phone' => null
      public 'mobile' => null
      public 'website' => null
      public 'twitter' => null
    
  • user.save_profile - 更新个人资料信息

    $profile = array('description' => 'description test',
    				'briefdescription' => 'briefdescription test',
    				'location' => 'India',
    				'interests' => 'my interest',
    				'skills' => 'my skills',
    				'contactemail' => 'myemail@email.com',
    				'phone' => '01234567890',
    				'mobile' => '11234567890',
    				'website' => 'http://mywebsite.com',
    				'twitter' => 'tweet',
    				);
    $params = array('username' => $this->user->username,
    				'profile' => $profile
    				);	
    $info = $client->post('user.save_profile', $params);
    var_dump($info);
    
    string 'Success' (length=7)
    
  • user.get_user_by_email - 获取所有使用电子邮件ID注册的用户

    $params = array('email' => 'tachyon.saket@gmail.com');
    $info = $client->get('user.get_user_by_email', $params);
    var_dump($info);
    
    array
    	0 => string 'Admin' (length=5)
    
  • user.check_username_availability - 检查用户名的可用性

    $params = array('username' => 'admin');	
    $info = $this->client->get('user.check_username_availability', $params);
    var_dump($info);
    
    boolean false
    
  • user.register - 注册用户

    $params = array('name' => 'test',
    				'email' => 'test2@test.org',
    				'username' => 'test2',
    				'password' => 'password',
    				);	
    $info = $this->client->get('user.register', $params);
    var_dump($info);
    
    object(stdClass)
    	boolean success true
    	int guid 8654
    
  • user.friend.add - 将用户添加为好友

    $params = array('username' => array ('type' => 'string'),
    				'friend' => array ('type' => 'string'),
    				);	
    $info = $this->client->post('user.friend.add', $params);
    var_dump($info);
    
    object(stdClass)
    	boolean success true
    	string message 'Successfully Added'
    
  • user.friend.remove - 从好友中删除用户

    $params = array('username' => array ('type' => 'string'),
    				'friend' => array ('type' => 'string'),
    				);	
    $info = $this->client->post('user.friend.remove', $params);
    var_dump($info);
    
    object(stdClass)
    	boolean success true
    	string message 'Successfully Removed'
    
  • user.friend.get_friends - 获取用户的朋友

    $params = array('username' => 'admin',
    				'limit' => 1,
    				'offset' => 0,
    				);
    $info = $this->client->get('user.friend.get_friends', $params);
    var_dump($info);
    
    object(stdClass)[334]
      public '3393' => 
    	object(stdClass)[300]
    	  public 'username' => string 'Tachyon' (length=19)
    	  public 'name' => string 'Saket Saurabh' (length=16)
    
  • user.friend.get_friends_of - 获取将某个用户设为好友的人

    $params = array('username' => 'tachyon',
    				'limit' => 1,
    				'offset' => 0,
    				);
    $info = $this->client->get('user.friend.get_friends', $params);
    var_dump($info);
    
    object(stdClass)[334]
      public '3393' => 
    	object(stdClass)[300]
    	  public 'username' => string 'admin' (length=19)
    	  public 'name' => string 'Administrator' (length=16)
    

博客

  • blog.save_post - 创建博客帖子

    $params = array('username' => 'admin',
    				'title' => 'Test blog post',
    				'text' => 'text of blog post',
    				),
    $info = $this->client->get('blog.save_post', $params);
    var_dump($info);
    
    object(stdClass)
    	public 'success' => boolean true
    	public 'message' => string 'Successfully saved the blog post.' (length=33)
    
  • blog.get_post - 读取博客帖子

    $params = array('guid' => 53,
    				'username' => 'admin'
    				),
    $info = $this->client->get('blog.get_post', $params);
    var_dump($info);
    
    object(stdClass)[3]
      public 'title' => string 'This is a new blog' (length=18)
      public 'content' => string 'this is the content of the latest blog' (length=38)
      public 'excerpt' => string '' (length=0)
      public 'tags' => string 'blog' (length=4)
      public 'owner_guid' => string '43' (length=2)
      public 'access_id' => string '2' (length=1)
      public 'status' => string 'published' (length=9)
      public 'comments_on' => string 'On' (length=2)
    
  • blog.delete_post - 删除博客帖子

    $params = array('guid' => 53,
    				'username' => 'admin'
    				);
    $info = $this->client->post('blog.delete_post', $params);
    var_dump($info);
    
    object(stdClass)
    	public 'success' => boolean true
    	public 'message' => string 'Blog post deleted.' (length=18)
    
  • blog.get_friends_posts - 获取朋友的最新博客帖子

    $params = array('username' => 'admin',
    				'limit' => 1,
    				'offset' => 0,
    				);
    $info = $this->client->get('blog.get_friends_posts', $params);
    var_dump($info);
    
    object(stdClass)[3]
      public '55' => 
    	object(stdClass)[4]
    	  public 'time_created' => string '1310124191' (length=10)
    	  public 'title' => string 'This is a new blog' (length=18)
    	  public 'content' => string 'this is the content of the latest blog' (length=38)
    	  public 'excerpt' => string '' (length=0)
    	  public 'tags' => string 'blog' (length=4)
    	  public 'owner_guid' => string '43' (length=2)
    	  public 'access_id' => string '2' (length=1)
    	  public 'status' => string 'published' (length=9)
    	  public 'comments_on' => string 'On' (length=2)
    
  • blog.get_latest_posts - 获取用户或所有用户的最新博客帖子

    $params = array('username' => 'admin',
    					'limit' => 1,
    					'offset' => 0,
    				);
    $info = $this->client->get('blog.get_latest_posts', $params);
    var_dump($info);
    
    object(stdClass)[3]
      public '49' => 
    	object(stdClass)[4]
    	  public 'time_created' => string '1310027828' (length=10)
    	  public 'title' => string 'title' (length=5)
    	  public 'content' => string 'text' (length=4)
    	  public 'excerpt' => string 'excerpt' (length=7)
    	  public 'tags' => string 'tags' (length=4)
    	  public 'owner_guid' => string '36' (length=2)
    	  public 'access_id' => string '2' (length=1)
    	  public 'status' => string 'published' (length=9)
    	  public 'comments_on' => string 'On' (length=2)
    

群组

  • group.join - 加入群组

    $params = array('username' => 'tachyon',
    				'groupid' => 72,
    				);
    $info = $this->client->post('group.join', $params);
    var_dump($info);
    
    object(stdClass)
    	public 'success' => boolean true
    	public 'message' => string 'Successfully joined group!' (length=26)  
    
  • group.leave 离开群组

    $params = array('username' => 'tachyon',
    				'groupid' => 72,
    				);
    $info = $this->client->post('group.leave', $params);
    var_dump($info);
    
    object(stdClass)
    	public 'success' => boolean true
    	public 'message' => string 'Successfully left group' (length=23)
    
  • group.forum.save_post 在群组中发布新主题

    $params = array('username' => 'admin',
    					'groupid' => 71,
    					'title' => 'testing post',
    					'desc' => 'hello i am testing web services',
    				);
    $info = $this->client->post('group.forum.save_post', $params);
    var_dump($info);
    
    object(stdClass)
    	public 'success' => boolean true
    	public 'message' => string 'The discussion topic was created.' (length=33)
    
  • group.forum.delete_post 从群组中删除主题

    $params = array('username' => 'admin',
    				'topicid' => 84,
    				);
    $info = $this->client->post('group.forum.delete_post', $params);
    var_dump($info);
    
    object(stdClass)
    	public 'success' => boolean true
    	public 'message' => string 'Discussion topic has been deleted.' (length=34)
    
  • group.forum.get_latest_post 获取群组中的最新帖子

    $params = array('groupid' => 47,
    				'limit' => 1,
    				'offset' => 0,
    				);
    $info = $this->client->get('group.forum.get_latest_post', $params);
    var_dump($info);
    
    object(stdClass)[3]
      public '56' => 
    	object(stdClass)[4]
    	  public 'title' => string 'test' (length=4)
    	  public 'description' => string '<p>test</p>' (length=11)
    	  public 'owner_guid' => string '36' (length=2)
    	  public 'container_guid' => string '47' (length=2)
    	  public 'access_id' => string '2' (length=1)
    	  public 'time_created' => string '1310144929' (length=10)
    	  public 'time_updated' => string '1310144929' (length=10)
    	  public 'last_action' => string '1310321462' (length=10)
    
  • group.forum.get_reply 获取帖子的回复

    $params = array('postid' => 56,
    				  'limit' => 1,
    				  'offset' => 0,
    				);
    $info = $this->client->get('group.forum.get_replies', $params);
    var_dump($info);
    
    object(stdClass)[3]
      public '2' => 
    	object(stdClass)[4]
    	  public 'value' => string '<p>this i smy reply</p>' (length=23)
    	  public 'name' => string 'group_topic_post' (length=16)
    	  public 'enabled' => string 'yes' (length=3)
    	  public 'owner_guid' => string '36' (length=2)
    	  public 'entity_guid' => string '56' (length=2)
    	  public 'access_id' => string '2' (length=1)
    	  public 'time_created' => string '1310310194' (length=10)
    	  public 'name_id' => string '71' (length=2)
    	  public 'value_id' => string '70' (length=2)
    	  public 'value_type' => string 'text' (length=4)
    
  • group.forum.save_reply 发布回复

    $params = array('username' => 'admin',
    					'postid' => 56,
    					'text' => 'My reply',
    				);
    $info = $this->client->post('group.forum.save_reply', $params);
    var_dump($info);
    
    object(stdClass)
    	public 'success' => boolean true
    	public 'message' => string 'Successfully posted reply' (length=25)
    
  • group.forum.delete_reply 删除回复

    $params = array('username' => 'admin',
    				'id' => 6,
    				);
    $info = $this->client->post('group.forum.delete_reply', $params);
    var_dump($info);
    
    object(stdClass)
    	public 'success' => boolean true
    	public 'message' => string 'Discussion reply has been deleted.' (length=34)
    

线缆

  • wire.save_post 发布线缆帖子

    $params = array('username' => 'admin',
    				'text' => 'test wire post',
    				);
    $info = $this->client->post('wire.save_post', $params);
    var_dump($info);
    
    object(stdClass)
    	public 'success' => boolean true
    	public 'message' => string 'succesfully saved' (length=17)
    
  • wire.get_posts 读取用户的最新线缆帖子

    $params = array('username' => 'admin',
    				);
    $info = $this->client->get('wire.get_post', $params);
    var_dump($info);
    
    object(stdClass)[3]
      public 'guid' => string '64' (length=2)
      public 'time_created' => string '1310558739' (length=10)
      public 'description' => string 'wire post' (length=9)
    
  • wire.get_friends_posts 读取朋友的最新线缆帖子

    $params = array('username' => 'admin',
    				'limit' => 1,
    				'offset' => 0,
    				);
    $info = $this->client->get('wire.get_friends_posts', $params);
    var_dump($info);
    
    object(stdClass)[3]
      public '64' => 
    	object(stdClass)[4]
    	  public 'time_created' => string '1310558739' (length=10)
    	  public 'description' => string 'wire post' (length=9)
    
  • wire.delete_posts 删除朋友的线缆帖子

    $params = array('username' => 'admin',
    				'wireid' => 64,
    				);
    $info = $this->client->post('wire.delete_posts', $params);
    var_dump($info);
    
    object(stdClass)
    	public 'success' => boolean true
    	public 'message' => string 'The wire post was successfully deleted.' (length=39)
    

文件

  • file.get_files 获取所有用户或特定用户的文件列表

    $params = array('limit' => 1,
    				  'offset' => 0,
    				);
    $info = $this->client->get('wire.get_files', $params);
    var_dump($info);
    
    object(stdClass)[3]
      public '58' => 
    	object(stdClass)[4]
    	  public 'title' => string 'deploy' (length=6)
    	  public 'owner_guid' => string '43' (length=2)
    	  public 'container_guid' => string '43' (length=2)
    	  public 'access_id' => string '2' (length=1)
    	  public 'time_created' => string '1310301409' (length=10)
    	  public 'time_updated' => string '1310301409' (length=10)
    	  public 'last_action' => string '1310301409' (length=10)
    
  • file.get_files_by_friend 获取朋友的文件列表

    $params = array('username' => 'admin',
    				'limit' => 1,
    				'offset' => 0,
    				);
    $info = $this->client->get('wire.get_files_by_friend', $params);
    var_dump($info);
    
    object(stdClass)[3]
      public '58' => 
    	object(stdClass)[4]
    	  public 'title' => string 'deploy' (length=6)
    	  public 'owner_guid' => string '43' (length=2)
    	  public 'container_guid' => string '43' (length=2)
    	  public 'access_id' => string '2' (length=1)
    	  public 'time_created' => string '1310301409' (length=10)
    	  public 'time_updated' => string '1310301409' (length=10)
    	  public 'last_action' => string '1310301409' (length=10)
    

  • likes.add 赞一个实体

    $params = array('entity_guid' => 64),
    				);
    $info = $this->client->post('likes.add', $params);
    var_dump($info);
    
    object(stdClass)
    	public 'success' => boolean true
    	public 'message' => string 'You now like this item' (length=22)
    
  • likes.delete 取消赞一个实体

    $params = array('entity_guid' => 64),
    				);
    $info = $this->client->post('likes.add', $params);
    var_dump($info);
    
    object(stdClass)
    	public 'success' => boolean true
    	public 'message' =>	string 'Your like has been removed' (length=26)
    
  • likes.count 实体的赞数量

    $params = array('entity_guid' => 64),
    				);
    $info = $this->client->get('likes.add', $params);
    var_dump($info);
    
    int 3