mixiのユーザーIDが仕様変更。

mixiのユーザーIDが仕様変更された

http://developer.mixi.co.jp/appli/spec/pc/platformuserid

(数字型)12345

(文字型 13桁)a1b2c3d4e5f6g
に変更されるらしい。

string(390) "
{"entry":{
"thumbnailUrl":"http://aaa.jpg",
"nickname":"おがはむ",
"dateOfBirth":"1111-07-01",
"isViewer":"true",
"hasApp":"true",
"platformUserId":"xxxxxxxxxxxxxx", <=ここが追加された
"isOwner":"true",
"updated":"",
"id":"mixi.jp:xxxxx",
"birthday":"1111-07-01",,
"gender":"male",
"displayName":"おがはむ"},
"startIndex":0,"totalResults":1}" 

entryの
platformUserId というのが新体系らしい。


修正したこと↓

//mysqlにカラム追加
//元々はmixi_account_codeとしていたのをmixi_account_idとして追加。

alter table members add mixi_account_id varchar(13) after mixi_account_code;

//controller[php]

<?php
$user_data = $this->oauth_get_user_account($mixi_account_code);
$mixi_account_id = $user_data['platformUserId'];
$this->Members->update_mixi_login_name($mixi_account_code,$mixi_account_id);
?>

//oauth取得用メソッド[php]

<?php
	function oauth_get_user_account($mixi_account_code){
		$api = new OpensocialGetUserRestfulAPI($mixi_account_code);
		$data = $api->get();
		$json = new Services_JSON;
		$decode_data = $json->decode($data,true);
		$user_data['nickname'] = $decode_data->entry->nickname;
		$user_data['thumbnailUrl']= $decode_data->entry->thumbnailUrl;
		//->>ここを追記
		$user_data['platformUserId']= $decode_data->entry->platformUserId;
		return $user_data;
	}
?>

//OpensocialGetUserRestfulAPIのコンポーネント[php]

<?php
require_once(BASE_DIR.'/cake/app/controllers/components/OAuth.php');
define(_CONSUMER_KEY_, '****************');
define(_CONSUMER_SECRET_, '****************');


class OpensocialGetUserRestfulAPI
{
   private $_base_feed  = NULL;
   private $_consumer  = NULL;
   private $_viewer_id   = NULL;

   public function __construct($viewer_id=NULL)
   {
       if (!$viewer_id && is_null($viewer_id)) return false;
       $this->_viewer_id  = $viewer_id;
       $this->_base_feed = sprintf('http://api.mixi-platform.com/os/0.8/people/@me/@self');
   }

   public function get()
   {
       try{
			$params = array(
				'xoauth_requestor_id' => $this->_viewer_id,
				'fields' => 'platformUserId' //<-ここを追記
			);

			$this->_consumer = new OAuthConsumer(_CONSUMER_KEY_,_CONSUMER_SECRET_, NULL);
			$request = OAuthRequest::from_consumer_and_token(
			$this->_consumer, NULL, 'GET', $this->_base_feed, $params);

			// Sign the constructed OAuth request using HMAC-SHA1
			$request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(),
                                   $this->_consumer, NULL);

           // Make signed OAuth request to the Contacts API server
			$url  = $this->_base_feed . '?' . $this->implode_assoc('=', '&', $params);
			$curl = curl_init($url);
			curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
			curl_setopt($curl, CURLOPT_FAILONERROR, false);
			curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
			curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
			$auth_header = $request->to_header();
			if ($auth_header) {
				curl_setopt($curl, CURLOPT_HTTPHEADER, array($auth_header));
			}

			$response = curl_exec($curl);
			if (!$response) {
				$response = curl_error($curl);
			}
			curl_close($curl);
       } catch (Exception $e) {
           var_dump($e);
           return false;
       }
       return $response;
   }

   function implode_assoc($inner_glue, $outer_glue, $array, $skip_empty=false)
   {
       $output=array();
       foreach ($array as $key => $item) {
           if (!$skip_empty || $item) {
               $output[] = $key. $inner_glue. urlencode($item);
           }
       }
       return implode($outer_glue, $output);
   }
}
?>