Skip to main content

How to Use the RESTful API

The RESTful API is also available in the PC version of the Mobage platform as a means for calling APIs from partner servers.
The following are available for the PC version.

An OAuth Signature must be added in a RESTful API request. Please also specify the application ID for the xoauth_requestor_id at that time.

See here for information on how to generate an OAuth Signature.

Sample​

The method for acquiring profile information of users who use the People API is as follows.

Perl: Please use OAuth::Lite module version 1.24 or later.

use strict;
use warnings;

use OAuth::Lite::Consumer;
use JSON;

my $consumer_key = 'YOUR CONSUMER KEY';
my $consumer_secret = 'YOUR CONSUMER SECRET';
my $app_id = 00000000; # YOUR APPLICATION ID
my $user_id = 00000000; # YOUR USER ID
my $base_url = 'http://app.sb.mbga-platform.jp/social/api/restful/v2';
my $url = "$base_url/people/$user_id/\@self";
my $method = 'GET';

my $consumer = OAuth::Lite::Consumer->new(
consumer_key => $consumer_key,
consumer_secret => $consumer_secret,
);

my $res = $consumer->request(
method => $method,
url => $url,
params => { xoauth_requestor_id => $app_id, },
);

my $person = decode_json( $res->content );

PHP: The OAuth library is available here.

<?php
require_once 'OAuth.php';

$consumer_key = 'YOUR CONSUMER KEY';
$consumer_secret = 'YOUR CONSUMER SECRET';
$app_id = 00000000; // YOUR APPLICATION ID
$user_id = 00000000; // YOUR USER ID
$base_url = 'http://app.sb.mbga-platform.jp/social/api/restful/v2';
$url = "$base_url/people/$user_id/@self?xoauth_requestor_id=$app_id";
$method = 'GET';

$consumer = new OAuthConsumer($consumer_key, $consumer_secret, NULL);
parse_str(parse_url($url, PHP_URL_QUERY), $params);
$request = OAuthRequest::from_consumer_and_token($consumer, NULL, $method, $url, $params);
$request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, NULL);
$auth_header = $request->to_header();

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_ENCODING , "gzip");
curl_setopt($curl, CURLOPT_HTTPHEADER, array($auth_header));
$response = curl_exec($curl);
curl_close($curl);

$person = json_decode($response);
?>

Revision History​

  • 12/2010
    • Initial Release.