Skip to content

Instantly share code, notes, and snippets.

@oh-sky
Created January 8, 2014 14:40
Show Gist options
  • Save oh-sky/8317800 to your computer and use it in GitHub Desktop.
Save oh-sky/8317800 to your computer and use it in GitHub Desktop.
はてな認証APIを使って、はてなIDを取得するテスト
<?php
$apiKey = '';
$apiSecret = '';
if (isset($_GET['cert'])) {
$apiSig = md5($apiSecret . 'api_key' . $apiKey . 'cert' . $_GET['cert']);
$jsonString = file_get_contents("http://auth.hatena.ne.jp/api/auth.json?api_key={$apiKey}&cert={$_GET['cert']}&api_sig={$apiSig}");
$obj = json_decode($jsonString);
if (!$obj->has_error) {
echo file_get_contents("http://b.hatena.ne.jp/{$obj->user->name}/rss");
exit();
}
}
$apiSig = md5($apiSecret . 'api_key' . $apiKey);
$authUrl = "http://auth.hatena.ne.jp/auth?api_key={$apiKey}&api_sig={$apiSig}";
header("Location: {$authUrl}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment