Skip to content

Instantly share code, notes, and snippets.

@kawahara
Created March 11, 2010 04:15
Show Gist options
  • Save kawahara/328816 to your computer and use it in GitHub Desktop.
Save kawahara/328816 to your computer and use it in GitHub Desktop.
<?php
// OpenSocial RESTful APIサンプル (2-legged OAuth)
// ライブラリとして http://oauth.googlecode.com/svn/code/php/ を利用しています。
include_once('lib/OAuth.php');
define('CONSUMER_KEY', '#CONSUMER_KEY#');
define('CONSUMER_SECRET', '#CONSUMER_SECRET#');
define('BASE_URL', '#BASE_URL#');
$consumer = new OAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
$request = OAuthRequest::from_consumer_and_token(
$consumer,
null,
'GET',
BASE_URL.'/api.php/social/rest/people/@me/@self'
);
$request->set_parameter('xoauth_requestor_id', 1);
$request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, null);
$res = do_get($request->get_normalized_http_url(), $request->to_postdata());
var_dump($res);
function do_get($uri, $data = '')
{
$h = curl_init();
curl_setopt($h, CURLOPT_URL, $uri.'?'.$data);
curl_setopt($h, CURLOPT_POST, false);
curl_setopt($h, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($h);
curl_close($h);
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment