h2ospace

foursquareã??ã??ã?§ã??ã?¯ã?¤ã??ã??ã??ã??ã??ã??ã??ã??ã??ã?°ã?©ã?? with CakePHP

2010-02-15 10:00:58

ã??ã??ã??Twitterã?¨ã??ã?¦å??é??ã??ã??foursquareã??ç§?ã??大æ?¨ç?®ã??ã?¦ã??ã??ã??ã??

ã??ã?®foursquareã??APIã??ä¸?è?¬ã??å?¬é??ã??ã?¦ã??ã?¦ã??ã??ã?§ã??ã?¯ã?¤ã??ã??ã??ã??ã??ã??ã??ã?®è¿?å??ã??ã?§ã??ã??ã??ã?¦ã?®æ©?è??ã??å?©ç?¨ã??ã??ã??ã?¨ã??å?ºæ??ã??ã??ã??ã??ã??ã?§ã??æ?©é??ã??ã??ã??ã??ã??ã??ã?°ã?©ã??ã??ä??ã?£ã?¦ã?¿ã??ã??ã??ã??ä¸?å®?å®?ã??ã??ã??ã??ã??ã??ã??ã??ã??ã??ã?¡ã??ã??ã??ã?©ã??ã??ã??

ã?§ã?¯ã??è??ã??解説ã??ã??

APIã?®ã??ã??ã??ã?¢ã??ã?¯ã??ã?¡ã??ã??ã??ã??ã??ã??ã??ã??ã??ã??@fawã??ã??ã??ã??æ??æ?¬èª?è¨?ã??ã??ã?¦ã??ã??ã?¦ã??ã??ã??ã??

OAuthã??ä?¿ã?£ã??æ??æ??ã??ã??ã??ã?®ã?§ã??ã??ã??ã?¡ã??ã?£ã?¨é?£ã??ã??ã?®ã?§ã??ã??ã??ã?§ã?¯ BASICèª?è¨?ã??ä?¿ã??æ??æ??ã??試ã??ã??ã??ã??ã?? ã??ã??ã?¯ã??ã?°ã?¤ã??ã?¨ã??å??è£?ã?®å??å??ã??ã??ã??ã??ã?¯ã??venuesã??ã?¨ã??ã??ã?¡ã??ã??ã??ã??ä?¿ã??ã??ã??ã??ã??ã??ã??ã??GETã?§ç?¯åº¦ã??ç??度ã??ã??ã?°ã?¤ã??æ??å?±ã??é??ã??è??ã??ã?®ã?§ã??ã??ã??CakePHPã?§ã?¯HTTPé??ä¿¡ã??è¡?ã??ã??ã??ã??ã??CakeSocketã??ã?¨ã??ã??ã??ã?®ã??æº?å??ã??ã??ã?¦ã??ã??ã?®ã?§ã??ã??ã??ã??ä?¿ã??ã??ã??ã??次ã?®ã??ã??ã?ªæ??ã??ã??

uses('http_socket', 'Xml');
$socket = new HttpSocket();

$url = 'http://api.foursquare.com/v1/venues';;
$query = array(
	'geolat'=>$this->data['Clip']['lat'],
	'geolong'=>$this->data['Clip']['lon']
);
$res = $socket->get($url, $query, array(
	'auth'	=> array(
		'user'	=> $this->data['Clip']['username'],
		'pass'	=> $this->data['Clip']['password']
	)
));

// get XML
$xml = new Xml($res);

ã??ã??ã?§ã??$xmlã??ã??XMLã?®è§£æ??ã??ã??ã??ã?®ã??å?ºã??ã?®ã?§ã??ã??ã??ã?§ã?ªã??ã??ã??æ§?ç¯?ã??ã?¦è¡?ã??ã??ã??ã?? ã??ã?§ã??ã?¯ã?¤ã??ã??ã?¯ã??Venue IDã?¨å??ã?°ã??ã??ã??å?´æ??ã??ã?¨ã??å??ã??æ?¯ã??ã??ã??IDã??渡ã??ã?®ã?§ã??ã??ã??ã??ã?©ã?¸ã?ªã??ã??ã?¯ã??ã?ªã?©ã?§æ¸¡ã??ã?ªã??ã??ã??shoutï??ã?¤ã?¶ã??ã??ï??ã??ã??渡ã??ã?¦ã??ä??度ã?¯ã??checkinã??ã?¡ã??ã??ã??ã??ä?¿ã??ã??ã??ã??

uses('http_socket', 'Xml');
$socket = new HttpSocket();

if ($this->data) {
	$url = 'http://api.foursquare.com/v1/checkin';;
	$query = array(
		'vid'	=> $this->data['Clip']['id'],
		'shout'	=> $this->data['Clip']['shout']
	);
	$res = $socket->post($url, $query, array(
		'auth'	=> array(
			'user'	=> $user['Clip']['username'],
			'pass'	=> $user['Clip']['password']
		)
	));

	$this->render('thanks');
}

ã??ã??ã?§OKã??ã??ã?§ã??ã?¯ã?¤ã??ã??ã??ã??ã?¨ã??å?ºæ??ã??ã??ã??

ã??ã??ã??ä?¿ã??ã?°ã??å??ã??ã?ªå?´æ??ã??ã??ã?§ã??ã?¯ã?¤ã??ã??ã??ã??ã?¨ã??ã?§ã??ã?¡ã??ã??ã??ã??ã?? ã?¢ã?ªã??ã?¤å??ä??ã?ªã?©ã??ä?¿ã??ã?ªã??ã??ã??ã??ã??æ?¨æ??ã??ã??ã??ã??ã??ï??ç¬?

ã??ã?¦ã??ã??ã??ã??ã?¯ã??ã?¡ã??ã??ã??ã?©ã??ã??ã??

※このエントリは ブロガーにより投稿されたものです。朝日インタラクティブ および ZDNet Japan編集部の見解・意向を示すものではありません。
  • 新着記事
  • 特集
  • ブログ