Internet

You are currently browsing the articles from KomKid.Net matching the category Internet.

noknok.in.th API #03 Profile

มาต่อกันด้วย Profile ครับท่าน

URL: http://api.noknok.in.th/rest/profile
Format: xml
Method(s): GET
Parameters:
* authToken (required)
Return:
* User’s profile data

เริ่มด้วยการลองคลิกเข้าไปแบบตอนที่ Authen แต่คราวนี้กลับได้ผลดังรูป
noknok_api_profile_fail

แสดงว่าต้องเริ่มสื่อสารกันเป็นจริงเป็นจังแล้วล่ะ
ตามคู่มือที่เค้าบอกก็คือ format ของการสื่อสารกัน ก็คือ xml
ดังนั้นก็เลยต้องเลือกวิธีที่จะใช้ ซึ่งผมเลือกใช้ DOM ก็จัดการหา function มาใช้งานสำหรับดึงค่าจาก xml มาใช้

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function xml_to_result($dom) {
   $root = $dom->firstChild;
   foreach($root->attributes as $attr) $res[$attr->name] = $attr->value;
   $node = $root->firstChild;
   $i = 0;
   while($node) {
      switch($node->nodeName) {
         case 'Result':
         $subnode = $node->firstChild;
         while($subnode) {
            $subnodes = $subnode->childNodes;
            foreach($subnodes as $n) {
               if($n->hasChildNodes()) {
                  foreach($n->childNodes as $cn) $res[$i][$subnode->nodeName][$n->nodeName]=trim($cn->nodeValue);
               } else $res[$i][$subnode->nodeName]=trim($n->nodeValue);
            }
            $subnode = $subnode->nextSibling;
         }
         break;
         default:
         $res[$node->nodeName] = trim($node->nodeValue);
         $i--;
         break;
      }
      $i++;
      $node = $node->nextSibling;
   }
   return $res;
}

จากนั้นก็ทำการ authen ก่อน เพราะเจ้า profile นี่มันต้องการ authToken ซึ่งจะได้มาจากเจ้า auth อีกที ดังนี้

1
2
3
4
5
6
7
$base         = 'http://api.noknok.in.th/rest/auth';
$query_string = 'username=komkid&password=******';

$url = "$base?$query_string";

$xml = file_get_contents($url);
echo $xml;

ซึ่งก็ได้ผลดังนี้
noknok_api_profile_ok

แล้วก็ตามด้วยการขอดู profile ด้วย code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$base         = 'http://api.noknok.in.th/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"){
    $base         = 'http://api.noknok.in.th/rest/profile';
    $query_string = 'authToken='.$res["authToken"];

    $url = "$base?$query_string";
    $xml = file_get_contents($url);
    echo $xml;
}

ซึ่งก็ได้ผลดังรูปครับ
noknok_api_profile_result

หรือจะจัดรูปแบบในการแสดงผลซะหน่อยด้วย code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
$base         = 'http://api.noknok.in.th/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"){
    $base         = 'http://api.noknok.in.th/rest/profile';
    $query_string = 'authToken='.$res["authToken"];

    $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);
    echo "name : ".$res["name"]."<br>";
    echo "story: ".$res["story"]."<br>";
    echo "homepage : ".$res["homepage"]."<br>";
    echo "image : <img src=".$res["profile_image_url"].">";
}

ก็ได้ผลดังรูป
noknok_api_profile_show

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

noknok.in.th API #02 Authen

คราวนี้มาลองใช้งาน API ของ noknok.in.th กันบ้าง
เริ่มด้วยสิ่งที่จำเป็นต้องใช้ในครั้งนี้ (เฉพาะวิธีของผม) ก็คือ
1.Account ของ noknok.in.th
2.Server ที่ใช้งาน PHP และ DOM ได้ (ความจริงไม่ต้อง DOM ก็ได้ครับ แต่บังเอิญผมเริ่มด้วยเจ้านี่ ก็ขอแสดงด้วยเจ้า DOM นี่แหล่ะครับ)

เริ่มกันเลยนะครับ ตามที่ noknok.in.th เข้ามีคำแนะนำให้ที่ http://en.wikipedia.org/wiki/User:Noknokdev (API ของเค้าให้ใช้ผ่าน REST protocol ซึ่งมี link ให้ไปศึกษากันเองอยู่แล้ว)

อันดับแรกก็ลองงานกลุ่มของ Account Methods เริ่มด้วย

Authen
URL: http://api.noknok.in.th/rest/auth
Format: xml
Method(s): GET, POST
Parameters:
* username (required)
* password (required)
Return:
* authToken

ลองคลิกเข้าไปดูก็จะได้ popup สำหรับ login
noknok_api_auth1

และถ้าป้อน username และ password ถูกต้องก็จะได้ผล ดังรูป
noknok_api_auth_ok

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

noknok.in.th API #01 Start

micro blogging ที่ดังที่สุดตอนนี้ก็คงเป็น twitter แต่ในไทยเองก็มี noknok ที่หลายคนบอกว่าเป็น twitter clone
ประโยชน์หรือไอเดียในการใช้งาน ก็
1.Follow กันเองกับแฟน ใช้ส่ง sms หากันฟรี
2.ทำในลักษณะ groupmail สมัครแล้วก็แจก password กัน แล้วก็ update ข่าวสารกันทั้งก๊วน
3.โปรโมทเว็บ update web ทีก็ส่งข่าวสารให้พวกสาวกได้รับรู้
4.ฯลฯ ใครมีไอเดียในการใช้งานอื่น ๆ ก็บอกกันบ้างเด้อ

วิธีสมัครก็ง่ายแสนง่าย ตั้ง username > เลือกรหัสผ่าน > ใส่ email
จากนั้นก็เลือกผู้ที่เราจะติดตามข่าวสาร เลือกเอาว่าจะรับข้อความทางโทรศัพท์มั้ย
ขั้นตอนก็ง่าย ๆ คงไม่ต้องอธิบาย (เด็ก ๆ ก็ทำเป็น)

เอาไว้มาดูกันที่ตอนต่อไปเรื่องการใช้งาน API ดีกว่า

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

Google Gears

เพิ่งจะลอง load Google Gears มาลงเพื่อใช้งานในเมนู Turbo ของ WordPress 2.7 มาเมื่อไม่นานมานี้ ซึ่งก็ประทับใจในความรวดเร็วเป็นอย่างมาก
ล่าสุดก็ได้เพิ่งรับข่าว (ซึ่งตอนแรกคิดว่า ข่าวลือ) ว่า Gmail จะเปิดให้ใช้บริการแบบ Offline อีก โอ้ว แม่เจ้า ต้องลองซะแล้ว

และแล้วใน Labs ของ Account ผมก็มีให้เปิดใช้แล้ว (ไชโย)
offline-gmail

ยังไงก็ขอลองก่อนล่ะ แต่ inbox ขนาด 5GB ของผมนี่เวลาใช้ Offline จะเกิดผลยังไงน้อ

Written by Komkid on February 2nd, 2009 with no comments.
Read more articles on Internet and IT Tips.

Thai Language in Google Translate

และแล้วก็มาถึงกับ ภาษาไทย ใน Google Translate
google-translate-thai-01

google-translate-thai-02

คงจะเป็น beta test เพราะเปิดที่ทำงานใช้ได้ (net ของ TOT) แต่พอมาใช้ที่บ้านกลับไม่มีแฮะ (net ของ TRUE)

Written by Komkid on February 2nd, 2009 with no comments.
Read more articles on Internet.

« Older articles

Newer articles »