新浪微博开放平台旧版API中的PHP例程

相关文章:

一、PHP+新浪微博开放平台+新浪云平台(SAE)方案的基础
二、建立微博应用的过程
三、PHP SDK中Demo程序简析
四、进一步学习的走向和有用的资源
五、必须交待的几个问题
【PDF全文下载】


  本文是新浪微博旧版API中的PHP例程,可以作为初学时阅读和试探的参考材料。

  API 文档的旧版接口文档提供了一些PHP示例(新浪对PHP的支持最好),很方便用于学习。但是在新版API文档中,这些例子找不到了。另外,例子是通过接口组织的,这给初学者带来困难,我们希望通过要实现的功能来组织这些材料。例如,要实现转发一篇微博,能够很快地找到,这显然很诱人。

  烟台大学2008级学生高娜娜、孙芳丽、张肖对例程进行了整理并加入了适当的注释。

  本文的使用方法:阅读每一段代码,将代码写入前面的weibolist.php文件中,或者另建一个文件,在已经建好的应用中运行,调试、观察、改写。以此为基础,学习过程将加快,成为微博开发的高手。

  需要说明的是,下面的条目分类有与API文档V2不一致的地方,请带着质疑,对照着API文档使用下面的例子。


微博

 1.读取接口
//Statuses/counts
//批量获取指定微博的转发数评论数(读取接口)
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );
$u_id = "u_id";
$msg = $c->user_timeline($u_id);
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
}
if (isset($msg['error_code']) && isset($msg['error'])){
	echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
	return false;
} 
if (count($msg)> 1){
	$sid1 = $msg[0]['id'];
	$sid2 = $msg[1]['id'];
	$sid_total = $sid1.",".$sid2;
	$msg  = $c->get_count_info_by_ids($sid_total);
	if ($msg === false || $msg === null){
		echo "Error occured";
		return false;
	}
	if (isset($msg['error_code']) && isset($msg['error'])){
		echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
		return false;
	}
	foreach($msg as $data){
		$id = $data['id'];
		$num_comments = $data['comments'];
		$num_rts = $data['rt'];
		echo $id."=".$num_comments."&".$num_rts.";";
	}
}


//Statuses/show
//获取单条ID的微博信息,作者信息将同时返回(读取接口)
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );

$u_id = "用户ID";
$msg = $c->user_timeline($u_id);
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
}
if (isset($msg['error_code']) && isset($msg['error'])){
	echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
	return false;
}
if (count($msg)>0){
	$t_id = $msg[0]['id'];
	$msg = $c->show_status($t_id);
	if ($msg === false || $msg === null){
		echo "Error occured";
		return false;
	}
	if (isset($msg['error_code']) && isset($msg['error'])){
		echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
		return false;
	}
	if (isset($msg['id']) && isset($msg['text'])){
		echo($msg['id'].' : '.$msg['text']);
	}
}



2.写入接口

//Statuses/repost
// 转发一条微博信息(写入接口)
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );
$msg = $c->user_timeline();
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
} 
if (count($msg)> 1){
	$sid = $msg[1]['id'];
	echo($sid);
	$msg  = $c->repost($sid);
	if ($msg === false || $msg === null){
		echo "Error occured";
		return false;
	}
	echo($msg['id'].' : '.$msg['text']);
}

//Statuses/reply
//回复一条微博(写入接口)
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );
//to be filled in
$sid='sid';
$comment='comment';
$cid='cid';
$msg=$c->reply($sid, $comment,$cid);
echo($msg['text'];

//Statuses/comment destroy
//删除一条评论(写入接口)
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );
//comment ID
$c_id = "Comment ID";
$msg = $c->oauth->post("http://api.t.sina.com.cn/statuses/comment_destroy/".$c_id.".json");
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
}
if (isset($msg['error_code']) && isset($msg['error'])){
	echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
	return false;
}

//Statuses/comment(旧接口)
// 对一条微博信息进行评论
//comments/create 评论一条微博(写入接口)
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );
//发表新微博信息
$msg = $c->update("测试发表微博");
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
}
if (isset($msg['error_code']) && isset($msg['error'])){
	echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
	return false;
}
//微博id
$sid = $msg['id'];
echo($sid." : ".$msg['text']." ".$msg["created_at"]);
sleep(5);
//对刚发表的微博进行评论
$msg = $c->send_comment($sid,"测试评论",null);
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
}
if (isset($msg['error_code']) && isset($msg['error'])){
	echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
	return false;
}
echo($msg['id'].' : '.$msg['text'].'  '.$msg['created_at']);


//Statuses/repost
//转发一条微博信息(写入接口)
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );
$msg = $c->user_timeline();
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
} 
if (count($msg)> 1){
	$sid = $msg[1]['id'];
	echo($sid);
	$msg  = $c->repost($sid);
	if ($msg === false || $msg === null){
		echo "Error occured";
		return false;
	}
	echo($msg['id'].' : '.$msg['text']);
}


//Statuses/destroy
//删除微博信息(写入接口)
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );
//先发表一篇微博
$msg = $c->update("测试发表微博");
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
}
if (isset($msg['error_code']) && isset($msg['error'])){
	echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
	return false;
} 
echo($msg['id']." : ".$msg['text']." ".$msg["created_at"]);
//删除刚发表的微博
$c->destroy($msg['id']);
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
}
if (isset($msg['error_code']) && isset($msg['error'])){
	echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
	return false;
}
//user id
$uid = "User ID";
$msg = $c->user_timeline($uid);
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
}
if (isset($msg['error_code']) && isset($msg['error'])){
	echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
	return false;
} 
//遍历当前微博信息
foreach($msg as $data){
	echo($data['id']." : ".$data['text']." ".$data["created_at"]);
}

//statuses/upload
//上传图片并发布一条微博(写入接口)



//Statuses/update
//发布一条微博信息(写入接口)
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );
$msg = $c->update("测试发表微博");
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
}
if (isset($msg['error_code']) && isset($msg['error'])){
	echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
	return false;
} 
echo($msg['id']." 

用户

读取接口
//users/show
//根据用户ID获取用户资料(授权用户)
//获取用户信息(读取接口)
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );
//用户ID
$u_id = "u_id";
$msg = $c->show_user($u_id);
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
}
if (isset($msg['error_code']) && isset($msg['error'])){
	echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
	return false;
}
echo($msg['id'].' : '.$msg['name'].'  '.$msg['created_at']);




关系

关系读取接口

//Statuses/friends
//获取用户的关注列表(关注读取接口)
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );
//用户ID
$u_id = "User_ID";
$msg = $c->friends(false, false, $u_id);
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
}
if (isset($msg['error_code']) && isset($msg['error'])){
	echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
	return false;
}
foreach($msg as $friend){
	echo($friend['id'].' : '.$friend['name'].'  '.$friend['created_at'].' ;');
}


//Friendships/show
//获取两个用户关系的详细情况(关系状态读取接口)
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );

//关注对象的id
$u_id = "u_id";
$msg = $c->is_followed($u_id);
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
}
if (isset($msg['error_code']) && isset($msg['error'])){
	echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
	return false;
}
if (isset($msg['target'])){
	if (isset($msg['target']['followed_by'])){
		if ($msg['target']['followed_by'] === true){
			echo "Target is followed: true";
		} else {
			echo "Target is followed: false";
		}
	}
}


//friendships/exists(关注接口)
//是否关注某用户
//是否关注某用户(推荐使用friendships/show)
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );
//自己的id
$user_a = 'u_id';
//关注对象的id
$user_b= "u_id";
$msg = $c->oauth->get('http://api.t.sina.com.cn/friendships/exists.json?user_a='.$user_a.'&user_b='.$user_b);
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
}
if (isset($msg['error_code']) && isset($msg['error'])){
	echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
	return false;
}
if (isset($msg['friends'])){
	if ($msg['friends'] === true){
		echo "true";
	} else {
		echo "false";
	}
}


粉丝读取接口

//Statuses/followers
//返回用户关注对象列表,并返回最新微博文章。
//获取用户粉丝列表(粉丝读取接口)
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );

//用户ID
$u_id = "u_id";
$msg = $c->followers(false, false, $u_id);
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
}
if (isset($msg['error_code']) && isset($msg['error'])){
	echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
	return false;
}
foreach($msg as $follower){
	echo($follower['id'].' : '.$follower['name'].'  '.$follower['created_at'].' ;');
}


关系链读取接口
写入接口
//friendships/destroy
//消关注某用户(关系  写入接口)
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );
//关注用户的id
$u_id = "u_id";
$msg = $c->unfollow($u_id);
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
}
if (isset($msg['error_code']) && isset($msg['error'])){
	echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
	return false;
}
if (isset($msg['screen_name'])){
	echo('Unfollow Friend:'.$msg['screen_name']);
}

//friendships/create
//关注某用户(关系  写入接口)
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );
//关注用户的id
$u_id = "U_ID";
$msg = $c->follow($u_id);
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
}
if (isset($msg['error_code']) && isset($msg['error'])){
	echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
	return false;
}
if (isset($msg['screen_name'])){
	echo('New Friend:'.$msg['screen_name']);
}


账号
读取接口

//account/verify_credentials(旧版接口)
//account/get_uid(账号  读取接口)
//OAuth授权之后获取用户UID
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );

$msg = $c->verify_credentials();
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
}
if (isset($msg['error_code']) && isset($msg['error'])){
	echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
	return false;
}
if (isset($msg['name'])){
	echo($msg['name']);
}

//account/rate_limit_status(账号 读取接口)
//获取当前用户API访问频率限制
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );

$msg = $c->oauth->get("http://api.t.sina.com.cn/account/rate_limit_status.json");
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
}
if (isset($msg['error_code']) && isset($msg['error'])){
	echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
	return false;
}
if (isset($msg['hourly_limit'])){
	echo($msg['hourly_limit']);
}

收藏

读取接口

//favorites(收藏 读取接口)
//获取当前用户的收藏列表 
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );
$msg = $c->get_favorites();
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
}
if (isset($msg['error_code']) && isset($msg['error'])){
	echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
	return false;
}
foreach($msg as $status){
	if (isset($status['id']) && isset($status['text'])){
		echo($status['id'].' : '.$status['text'].' ; ');
	}	
}

写入接口
//favorites/destroy(收藏  写入接口)
//删除收藏
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );

//微博信息id
$sid='sid';
$msg = $c->remove_from_favorites( $sid );
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
}
if (isset($msg['error_code']) && isset($msg['error'])){
	echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
	return false;
}
if (isset($msg['text'])){
	echo($msg['text']);
}


//favorites/create(收藏 写入接口)
//添加收藏 
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );
//收藏id
$sid='sid';
$msg = $c->add_to_favorites( $sid );
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
}
if (isset($msg['error_code']) && isset($msg['error'])){
	echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
	return false;
}
if ($msg['text']){
	echo($msg['text']);
}


话题
  读取接口
  写入接口
标签
  读取接口
  写入接口
注册
  读取接口
搜索
  搜索联想接口
  搜索话题接口
推荐
  读取接口
  写入接口
提醒
  读取接口
公共服务
  读取接口)
地理信息
  基础位置读取接口
//location/Base/get_map_image(地理信息  基础位置读取接口)
//生成一张静态的地图图片


地标转换接口
POI数据读取接口

//pois/get_poi(POI数据处理接口)
//获取新增POI数据


//Pois/add_poi(POI数据处理接口)
//新增POI数据


POI数据搜索接口

//Pois/view(POI数据搜索接口)
//根据关键字和(或)分类,在一个矩形里进行搜索,返回相关的poi点信息


//pois/round(POI数据搜索接口)
//根据关键字和(或)分类,在中心点附近搜索,返回相关的poi点信息


//Pois/keyword(POI数据搜索接口)
//根据关键字和(或)分类进行搜索,返回相关的poi点信息


POI数据写入接口
移动服务读取接口

//Loc/get_location(移动定位接口)
// 根据基站、WIFI等其它数据,返回当前位置
//获取定位数据
//改为你的微博账号,用户名和密码之间用:隔开
$userPwd = '[email protected]:pwd';
//改为你微博应用的appkey
$appkey = '0123456789';
$url = "http://api.t.sina.com.cn/location/loc/get_location.json?source=$appkey";

$data = array(
 "version"=> "1.1.0",
 "host"=> "api.t.sina.com.cn/location/loc/",
 "radio_type"=> "gsm",
 "request_address"=> true,
 "decode_pos"=>true,
  "location"=>array( 
   "latitude"=>39.08943,
   "longitude"=>116.36843,
   "accuracy" =>678.0
 ),
"cell_towers"=>array(
	array (
     "cell_id"=> 4466,
     "location_area_code"=> 26630,
     "mobile_country_code"=> 460,
     "mobile_network_code"=> 0,
     "signal_strength"=> -60,
   ),
   	array (
     "cell_id"=> 4466,
     "location_area_code"=> 25054,
     "mobile_country_code"=> 460,
     "mobile_network_code"=> 0,
     "signal_strength"=> -70,
   )
 ),
 
 "wifi_towers"=>array(
   array(
     "mac_address"=> "00:0B:86:27:99:B0",
     "mac_name"=>"Sina-web",
     "signal_strength"=> 78,   
   ),
   array(
     "mac_address"=> "00:0B:86:28:7B:F0",
     "mac_name"=>"CMCC",
     "signal_strength"=> 90,
   )
 ) 
 );
$data = json_encode($data);

function curlPost($url,$userPwd,$data = '',$header = ''){
    $ch = curl_init() or die (curl_error()) ;
	curl_setopt($ch,CURLOPT_URL,$url);
	curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
	curl_setopt($ch,CURLOPT_TIMEOUT,30);
	if(!empty($userPwd)){
		curl_setopt($ch,CURLOPT_USERPWD,$userPwd);
	}
	if(!empty($data)){
		curl_setopt($ch,CURLOPT_POST,true);
		curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
	}
	if(!empty($header)){
		curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
	}
	$result = curl_exec($ch) or die (curl_error($ch));
	curl_close($ch);
	return $result;
}
$header = array('Content-type: application/json');  

$return = curlPost($url,$userPwd,$data,$header);


交通路线读取接口

地理位置信息接口错误代码及解释

OAuth 2.0接口(V2版接口将仅支持OAuth 2.0授权方式)
//Oauth2/authorize
response_type为token
//请求用户授权Token(登录/Oauth 2.0接口)
https://api.t.sina.com.cn/oauth2/authorize?client_id=123050457758183&redirect_uri=http://www.example.com/response&response_type=token

//同意授权后会重定向
http://www.example.com/response#access_token=ACCESS_TOKEN&expires_in=250327040&refresh_token=REFRESH_TOKEN

response_type为code
//请求
https://api.t.sina.com.cn/oauth2/authorize?client_id=123050457758183&redirect_uri=http://www.example.com/response&response_type=code

//同意授权后会重定向
http://www.example.com/response&code=CODE

//oauth/access_token
//获取授权过的Access Token
$o = new WeiboOAuth( WB_AKEY , 
                     WB_SKEY , 
                     $_SESSION['keys']['oauth_token'] , 
                     $_SESSION['keys']['oauth_token_secret']  );

$last_key = $o->getAccessToken(  $_REQUEST['oauth_verifier'] ) ;
echo($last_key['oauth_token']);


旧版API接口

微博访问接口

//user/statuses/id(微博访问接口)
//根据微博ID和用户ID跳转到单条微博页面
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );
$msg = $c->user_timeline();
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
} 
if (count($msg)> 0){
	$uid = 'User ID';
	$sid = $msg[0]['id'];
	$msg  = $c->get_comments_by_sid($sid);
	if ($msg === false || $msg === null){
		echo "Error occured";
		return false;
	}
	$url = "http://api.t.sina.com.cn/".$uid."/statuses/".$sid;
	//To achieve redirection, header() must be called before any actual output is sent, such as HTML tags
	header( 'Location:'.$url );
}


账号接口
//account/end_session
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );

$msg = $c->oauth->post("http://api.t.sina.com.cn/account/end_session.json");
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
}
if (isset($msg['error_code']) && isset($msg['error'])){
	echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
	return false;
}
if (isset($msg['name'])){
	echo($msg['name']);
}

//account/update_profile_image
//更改头像(账号接口)(从旧版接口找到的)
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );
$pic_path = 'pic_path';
$msg = $c->update_avatar($pic_path);
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
}
if (isset($msg['error_code']) && isset($msg['error'])){
	echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
	return false;
}
if (isset($msg['name'])){
	echo("Successfully upload the status to [".$msg['name'].'].');
}

//account/update_profile
//更改资料(同上)
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );
//name you want to change to
$name = 'name';
//gender you want to change to
$gender = 'f';
$param = array();
$param['name'] = $name;
$param['gender']= $gender;
$msg = $c->oauth->post('http://api.t.sina.com.cn/account/update_profile.json',$param);
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
}
if (isset($msg['error_code']) && isset($msg['error'])){
	echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
	return false;
}
if (isset($msg['name'])){
	echo($msg['name']);
}


登录/OAuth接口
//oauth/access_token
//获取授权过的Access Token
$o = new WeiboOAuth( WB_AKEY , 
                     WB_SKEY , 
                     $_SESSION['keys']['oauth_token'] , 
                     $_SESSION['keys']['oauth_token_secret']  );

$last_key = $o->getAccessToken(  $_REQUEST['oauth_verifier'] ) ;
echo($last_key['oauth_token']);

//oauth/authorize
//请求用户授权Token
$o = new WeiboOAuth( WB_AKEY , WB_SKEY  );
$keys = $o->getRequestToken();
$aurl = $o->getAuthorizeURL( $keys['oauth_token'] ,false , 'http://localhost/callback.php');
echo($aurl);

//oauth/request_token
// 获取未授权的Request Token
$o = new WeiboOAuth( WB_AKEY , WB_SKEY  );
$keys = $o->getRequestToken();
echo($keys['oauth_token'].' : '.$keys['oauth_token_secret']);

//oauth/access_token(登录/OAuth接口)
//获取授权过的Access Token
$o = new WeiboOAuth( WB_AKEY , 
                     WB_SKEY , 
                     $_SESSION['keys']['oauth_token'] , 
                     $_SESSION['keys']['oauth_token_secret']  );

$last_key = $o->getAccessToken(  $_REQUEST['oauth_verifier'] ) ;
echo($last_key['oauth_token']);

空间计算接口
//Distance/distance line(空间计算接口)
//计算地图上线的长度



//Distance/distance po li(空间计算接口)
//计算地图上(x,y)到线的最近距离


//Distance/distance point(空间计算接口)
//计算地图上两点之间的距离



公交搜索接口
//Bus/station(公交搜索接口)
//公交站点名称搜索


//Bus/line(公交搜索接口)
//线路名称搜索


//Bus/transfer(公交搜索接口)
//根据起始id或坐标搜索公交换乘路线




地址转换接口
//Geocode/geo_to_address(地址转换接口)
//根据坐标返回地址信息



//Geocode/address_to_geo(地址转换接口)
//根据地址返回坐标的接口


//geocode/ip_to_geo(地址转换接口)
//根据ip返回地理信息





你可能感兴趣的:(PHP,微博应用)