มีโค้ด PHP ในการดึงค่าจาก wordpress ผ่าน XML-RPC มาฝากคับ

เริ่มโดย gilbert, 19 กุมภาพันธ์ 2011, 15:52:13

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

gilbert

เหมาะสำหรับเพื่อนๆ นักพัฒนาที่จะทำบอทนะคับ

แรกเลยให้เราทำการเปิด XML-RPC ที่ Wordpress ด้วยเมนู ตั้งค่า->การเขียน

มาดูโค้ดตัวอย่างกันคับ



/*URL ที่อยู่ WordPress*/
$BLOGURL = "http://localhost/wordpress";

function get_response($URL, $context) {
    if(!function_exists('curl_init')) {
    die ("Curl PHP package not installed\n");
    }

    /*Initializing CURL*/
    $curlHandle = curl_init();

    /*The URL to be downloaded is set*/
    curl_setopt($curlHandle, CURLOPT_URL, $URL);
    curl_setopt($curlHandle, CURLOPT_HEADER, false);
    curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
    curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $context);

    /*Now execute the CURL, download the URL specified*/
    $response = curl_exec($curlHandle);
    return $response;
}

function blogger_getPost($appkey,$postid, $username, $password, $toPublish) {
   global $BLOGURL;
   $request = xmlrpc_encode_request("blogger.getPost",
      array($appkey, $postid,$username, $password,  $toPublish));

    /*สร้าง request to wordpress XMLRPC */
    $xmlresponse = get_response($BLOGURL."/xmlrpc.php", $request);
    $response = xmlrpc_decode($xmlresponse);

    /*Printing the response on to the console*/
    print_r($response);
}

$appkey="";

$USERNAME = "xxxx";
$PASSWORD = "xxxx";

$postid = 2;

/* ถ้าต้องการเผยแพร่เลยให้เป็น true */
$toPublish = true;

blogger_getPost($appkey, $postid, $USERNAME, $PASSWORD, $toPublish);
echo "\n";
?>




เป็นภาคแรกนะคับ เด่วภาคต่อไปจะทำเรื่องการ POST ข้อมูล ติดตามได้ที่ ตัวอย่าง Code PHP นะคับ

BabyKoala

+1 ขอบคุณครับ ถึงไม่ค่อยรู้เรื่องก็จะพยายามดูฦครับ  :wanwan017:
Thaiseoboard สังคมแห่งการแบ่งปัน:)

kokarat

+1 ครับแต่จะไปดึงมาต้อง มี username+password ของเว็บนั้นๆ ใช่ไหมครับ

gilbert

อ้างถึงจาก: kokarat ใน 19 กุมภาพันธ์ 2011, 15:58:17
+1 ครับแต่จะไปดึงมาต้อง มี username+password ของเว็บนั้นๆ ใช่ไหมครับ

แม่นแล้วคับ ทำงานผ่าน XML-RPC โปรโตคอล  คับ  จริงมี Atom โปรโตคอล อีกตัว กำลังศึกษาอยู่คับ


cotton

ว่าแต่ตัวนี้มันใช้ทำอะไร  :P
ภาคต่อไปยังพอรู้ว่ามันเอาไว้ post ลง wp

รอภาคต่อครับ +1


KhunHen


hermiss


gilbert


mahaboyd

Internet Marketing Never Die!!~~   8)