noknok.in.th API #04 Update Status

มาต่อกันด้วย การ Update Status ของเราด้วย

new
URL: http://api.noknok.sanook.com/rest/message_new
Format: XML
Method(s): GET, POST
Parameters:
* authToken (required:GET)
* message (required:POST)
Return
* Sending message data

(ผ่านไปไม่กี่วัน URL เปลี่ยนซะแล้ว จาก http://api.noknok.in.th/rest/ เป็น http://api.noknok.sanook.com/rest)

ซึ่งคราวนี้จะต้องส่งแบบ POST เพราะฉะันั้นก็ต้องสร้าง FORM ไว้ส่ง
ก็เอาแบบง่าย ๆ นะครับ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$base         = 'http://api.noknok.sanook.com/rest/auth';
$query_string = 'username=komkid&password=******';
 
$url = $base.'?'.$query_string;
 
$xml = file_get_contents($url);
$dom = new DOMDocument('1.0', 'UTF-8');
if ($dom->loadXML($xml) === false) {
   die('Parsing failed');
}
 
$res = xml_to_result($dom);
if($res[stat] == 'ok'){
    $query_string = 'authToken='.$res[authToken];
    $str=<<<FORM
    Update Status <br>
    <form method="post" action="http://api.noknok.sanook.com/rest/message_new?$query_string">
    message : <input type="text" name="message"><br>
    <input type="submit" value="update">
    </form>

    FORM;
    echo $str;
}

noknok_update_status
ได้ผลดังรูป
noknok_update_status_ok

อ้อ อย่าลืมตั้งค่า Encoding เป็น UTF8 ด้วยนะครับ

Introduction
API Protocol
* Representational_State_Transfer(REST)
* HTTP Requests: Post and GET
Data Format
* XML, *Json, *RSS,*ATOM
Encoding
* UTF8


Written by Komkid on February 23rd, 2009 with no comments.
Read more articles on Internet and Programming.

Related articles

No comments

There are still no comments on this article.

Leave your comment...

If you want to leave your comment on this article, simply fill out the next form:

You have to be identified to write a comment.