Favorites/destroy
(→使用示例: 添加代码) |
(→Java示例) |
||
第111行: | 第111行: | ||
} | } | ||
} | } | ||
+ | ====PHP示例==== | ||
+ | <pre> | ||
+ | //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']); | ||
+ | } | ||
+ | </pre> |
2010年8月4日 (三) 14:16的版本
目录 |
favorites/destroy
删除微博收藏。注意:只能删除自己收藏的信息。
URL
curl http://api.t.sina.com.cn/favorites/destroy/id.format
格式
xml, json
HTTP请求方式
POST, DELETE
是否需要身份验证
true
请求数限制
true
请求参数
- id. 必须参数. 要删除的收藏微博信息ID.
o 示例: http://api.t.sina.com.cn/favorites/destroy/12345.json
返回结果
XML示例:
<?xml version="1.0" encoding="UTF-8"?><statuses> <status> <created_at>Thu Jan 07 17:45:11 +0800 2010</created_at> <id>142310</id> <text>测试</text> <source> <a id="10012" href="http://zhulei.com">zhulei</a> </source> <favorited>false</favorited> <truncated>false</truncated> <geo/> <in_reply_to_status_id></in_reply_to_status_id> <in_reply_to_user_id></in_reply_to_user_id> <in_reply_to_screen_name></in_reply_to_screen_name> <user> <id>11075</id> <screen_name>name_11075</screen_name> <name>name_11075</name> <province>0</province> <city>0</city> <location></location> <description></description> <url></url> <profile_image_url>http://tp4.sinaimg.cn/11075/50/0</profile_image_url> <domain>11075</domain> <gender></gender> <followers_count>28</followers_count> <friends_count>50</friends_count> <statuses_count>0</statuses_count> <favourites_count>32</favourites_count> <created_at>Thu Jan 01 08:00:00 +0800 1970</created_at> <following>false</following> <verified>true</verified> <geo_enabled>false</geo_enabled> </user> </status> <status>
使用示例
- xml:
curl -u user:password --http-request DELETE http://api.t.sina.com.cn/favorites/destroy/1472669360.xml
- json:
curl -u user:password --http-request DELETE http://api.t.sina.com.cn/favorites/destroy/1472669360.json
Java示例
请从 微博SDK开发包下载 下载Java SDK
代码示例如下:
package weibo4j.examples; import java.util.List; import weibo4j.Status; import weibo4j.Weibo; import weibo4j.WeiboException; public class DestroyFavorite { /** * 删除当前用户收藏的微博信息 * @param args */ public static void main(String[] args) { System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY); System.setProperty("weibo4j.oauth.consumerSecret", Weibo.CONSUMER_SECRET); try { Weibo weibo = getWeibo(true,args); weibo.destroyFavorite(Long.parseLong(args[2])); List<Status> list = weibo.getFavorites(); for(Status status : list) { System.out.println(status.toString()); } } catch (WeiboException e) { e.printStackTrace(); } } private static Weibo getWeibo(boolean isOauth,String[] args) { Weibo weibo = new Weibo(); if(isOauth) {//oauth验证方式 args[0]:访问的token;args[1]:访问的密匙 weibo.setToken(args[0], args[1]); }else {//用户登录方式 weibo.setUserId(args[0]);//用户名/ID weibo.setPassword(args[1]);//密码 } return weibo; } }
PHP示例
//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']); }