-
Notifications
You must be signed in to change notification settings - Fork 0
API Channel
bazingaterry edited this page Nov 28, 2016
·
6 revisions
This API need token otherwise it will return token invalid error.
{
"ret": 10,
"msg": "token invalid."
}return all channel
- type: UNSUBSCRIBE = 0, CREATER = 1, SUBSCRIBE = 2
# Install the Python Requests library:
# `pip install requests`
import requests
def send_request():
# Get Channels
# GET http://api.sysu.space/api/channel
try:
response = requests.get(
url="http://api.sysu.space/api/channel",
params={
"token": "3290ea5260335da58f5f221cd6302ace",
"type": "1",
},
)
print('Response HTTP Status Code: {status_code}'.format(
status_code=response.status_code))
print('Response HTTP Response Body: {content}'.format(
content=response.content))
except requests.exceptions.RequestException:
print('HTTP Request failed'){
"channels": [
{
"id": 1,
"type": 0,
"name": "SDCS",
"last_upate": "2016-11-27 12:23:32.0"
},
{
"id": 32,
"type": 1,
"name": "233 Miao",
"last_upate": "2016-11-27 01:06:15.0"
},
{
"id": 31,
"type": 1,
"name": "2333",
"last_upate": "2016-11-27 01:04:12.0"
},
{
"id": 10,
"type": 0,
"name": "SMIE",
"last_upate": "2016-11-27 00:00:00.0"
},
{
"id": 11,
"type": 0,
"name": "CC",
"last_upate": "2016-11-27 00:00:00.0"
},
{
"id": 12,
"type": 0,
"name": "WSN",
"last_upate": "2016-11-27 00:00:00.0"
},
{
"id": 13,
"type": 0,
"name": "Web",
"last_upate": "2016-11-27 00:00:00.0"
},
{
"id": 14,
"type": 1,
"name": "WSN Pre",
"last_upate": "2016-11-27 00:00:00.0"
}
],
"ret": 0,
"msg": "ok."
}new channel
- name
# Install the Python Requests library:
# `pip install requests`
import requests
def send_request():
# New Channel
# POST http://api.sysu.space/api/channel
try:
response = requests.post(
url="http://api.sysu.space/api/channel",
params={
"token": "3290ea5260335da58f5f221cd6302ace",
},
headers={
"Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
},
data={
"name": "HAHAHAH",
},
)
print('Response HTTP Status Code: {status_code}'.format(
status_code=response.status_code))
print('Response HTTP Response Body: {content}'.format(
content=response.content))
except requests.exceptions.RequestException:
print('HTTP Request failed'){
"ret":1,
"msg":"channel name has benn used."
}{
"channel": {
"id": 62,
"type": 1,
"last_upate": "2016-11-27 05:23:46"
},
"ret": 0,
"msg": "ok"
}return all users in the channel
to be done
join channel / exit channel
- action (0 for join and 1 for exit)
# Install the Python Requests library:
# `pip install requests`
import requests
def send_request():
# Join Channel
# POST http://api.sysu.space/api/channel/1
try:
response = requests.post(
url="http://api.sysu.space/api/channel/1",
params={
"token": "3290ea5260335da58f5f221cd6302ace",
},
headers={
"Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
},
data={
"action": "0",
},
)
print('Response HTTP Status Code: {status_code}'.format(
status_code=response.status_code))
print('Response HTTP Response Body: {content}'.format(
content=response.content))
except requests.exceptions.RequestException:
print('HTTP Request failed'){
"ret": 20,
"msg": "fail"
}{
"ret": 0,
"msg": "ok"
}