[PHP] Pownce API 2.0

Started by Teotónio Ricardo, March 01, 2008, 09:58:58 PM

Previous topic - Next topic

Teotónio Ricardo

Pequena implementação da Class da nova API do Pownce em PHP:










$pow = $_POST[\\'pown\\'];

$pown = utf8_encode($pow);

echo $pow;



/*



PHP Pownce Basic Authentication



There are a few steps in getting Pownce to communicate with your PHP application. I\\'ve had some time to work with the new API

release and am presenting the information here so that others may get their applications up in a quicker manner. An oAuth

document for use with Pownce and PHP will be released in the future as well.



Without further ado...



Pownce offers two forms of Authentication for use with its API, Basic HTTP and oAuth.



In order to successfully spawn connections and data transfer from Pownce the easiest method is Basic HTTP. With a fun little module

called libcurl we can get this up and running in no time.



Pownce  says it would like to see an app_key and a basic authentication header per get/post. This is where curl comes into play.



Curl allows us to connect and communicate with many different types of servers in many different types of protocols (php.net/curl). In

order to get this working with Pownce we can follow a little guidelines from the API.



"With each authenticated request, the parameter app_key must also be included. The app_key is the application key assigned when the

application was registered.

Developers will need to construct and send the appropriate authorization header. To construct the header:

append the username and password like username:password

base-64 encode the username:password

send the "Authorization" header with the value "Basic x" where x is the base-64 encoded username:password"

(api.pownce.com)





So lets make a connection..

*/







 

function pownce_data($config_datasource, $type = \\'post\\', $post_data = NULL) {

 

  $config_address   = \\'http://api.pownce.com/2.0/\\'; // Api link

  $username = \\'ALTERAAQUIOUSERNAME\\';

  $password = \\'ALTERAAQUIAPASSWORD\\';

  $config_userpass  = base64_encode($username.\\':\\'.$password); //Encode userinfo

  $config_address   .= $config_datasource; // Appened our datasource to url

  $headers[] = "Authorization: Basic ".$config_userpass; //set our header

  $chandle  = curl_init(); //Initialize curl resource

 

  curl_setopt($chandle, CURLOPT_RETURNTRANSFER, true);

  curl_setopt($chandle, CURLOPT_HTTPHEADER, $headers); //Append our headers to curl resource

  curl_setopt($chandle, CURLOPT_URL, $config_address); //Give curl resource our url

  if(!empty($type) && strtolower($type) == \\'post\\') {

curl_setopt($chandle, CURLOPT_POST, 1); //Set curl to POST method.

  }

  if(!empty($post_data) ){

curl_setopt($chandle, CURLOPT_POSTFIELDS, $post_data);

  }

 

  return $chandle;

}



echo $pown;

$post_data = \\'app_key=ALTERAAQUIAKEYDAAPI&note_to=public&note_body=\\'.$pown.\\'\\';

$pownce_curl = pownce_data(\\'send/message.xml\\',\\'post\\',$post_data);



$pownce_xml = curl_exec($pownce_curl);

curl_close($pownce_curl);



/*

From then on you can parse the xml using either Dom or SimpleXML

This is the easiest method for which you can connect to Pownce with PHP.

If you have any questions you can email me at nomspes@gmail.com



Happy Powncing!

*/



?>

putu

boas....

desculpa a ignorância, mas para que serve isso?  :evil:

Teotónio Ricardo

O Pownce ( www.pownce.com ) é um sistema de microblogging, onde em vez de escreveres grandes posts no teu blog, escreves apenas pequenas informações, como por exemplo a música que estás a ouvir, o site que estás a ver, o que estás a fazer, etc...

Esta API permite fazer isso através do teu site, sem ser necessário ires ao Pownce.com directamente. Com algum trabalho consigo criar um perfil no Pownce e com esta API enviar artigos do WebTuga para lá automaticamente fazendo parse da RSS feed.

putu

QuoteO Pownce ( www.pownce.com ) é um sistema de microblogging, onde em vez de escreveres grandes posts no teu blog, escreves apenas pequenas informações, como por exemplo a música que estás a ouvir, o site que estás a ver, o que estás a fazer, etc...

Esta API permite fazer isso através do teu site, sem ser necessário ires ao Pownce.com directamente. Com algum trabalho consigo criar um perfil no Pownce e com esta API enviar artigos do WebTuga para lá automaticamente fazendo parse da RSS feed.


ok... cenourinha obrigado pela explicação