清空新浪微博

// 1. 使用 chrome 打开 weibo.com (确保你登录了微博)
// 2. 打开调试窗口,在 console 中贴下面的代码后回车
// 3. 如需删除其他微博,请输入一下内容后回车:start(); 

let mids = [];
let midIndex = 0;
let timer = null;
let running = false;
let http = new XMLHttpRequest();

function cleanNextPage() {
    let url = 'https://weibo.com/p/100505' + $CONFIG['uid'] + '/home';
    http.open('GET', url, true);
    http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    http.send();
    http.onreadystatechange = function() {
        if (http.readyState != 4 || http.status != 200) {
            return;
        }

        let matches = http.responseText.match(/mid=([0-9]+)/g);
        if (matches == null) {
            stop('恭喜你,可以重新来过了。如果还有请再执行一遍 ');
            return;
        }
        
        let values = {};
        matches.forEach(function(match) {
            values[match.substr(4)] = 0;
        }, this);

        mids = Object.keys(values);
        timer = setInterval('deleteNextWeibo();', 1000);

        console.log('本页有 ' + mids.length + ' 条微博');
    }
}

function deleteNextWeibo() {
    if (midIndex >= mids.length) {
        mids = [];
        midIndex = 0;
        clearInterval(timer);
        setTimeout('cleanNextPage();', 1000);
        return;
    }

    deleteWeibo(mids[midIndex]);
    midIndex++;
}

function deleteWeibo(mid) {
    http.open('POST', 'https://weibo.com/aj/mblog/del?ajwvr=6', true);
    http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    http.send('mid=' + mid);
    http.onreadystatechange = function() {
        if (http.readyState != 4 || http.status != 200) {
            return;
        }

        let json = {}
        try {
            json = JSON.parse(http.responseText);
        } catch (error) {
            return;
        }

        if (json.code == 100000) {
            console.log('删除成功 - ' + mid);
        }
    }
}

function stop(message) {
    clearInterval(timer);
    running = false;
    console.log(message);
}

function start() {
    if (running) {
        console.log('进行中...');
        return;
    }

    console.log('开始删除');
    running = true;
    mids = [];
    midIndex = 0;
    cleanNextPage();
}

js文件源文件: https://raw.githubusercontent.com/pythias/weibo-start-over/master/weibo-start-over.js

1, 使用 chrome 打开 https://weibo.com 并登录 (https)
2, 打开调试窗口,复制 weibo-start-over.js 中的全部代码, 在 console 中粘贴代码后回车
3, 请在console输入 start()

新浪t.cn短网址接口(PHP)

使用前要先去申请API-KEY,或使用oAuth进行认证。
将长网址变为短网址的方法:

<?php
function shortenSinaUrl($long_url){
$apiKey=’API-KEY’;
$apiUrl=’http://api.t.sina.com.cn/short_url/shorten.json?source=’.$apiKey.’&url_long=’.$long_url;
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, $apiUrl);
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curlObj, CURLOPT_HEADER, 0);
curl_setopt($curlObj, CURLOPT_HTTPHEADER, array(‘Content-type:application/json’));
$response = curl_exec($curlObj);
curl_close($curlObj);
$json = json_decode($response);
return $json[0]->url_short;
}
?>

将短网址还原成长网址的方法:

<?php
function expandSinaUrl($short_url){
$apiKey=’API-KEY’;
$apiUrl=’http://api.t.sina.com.cn/short_url/expand.json?source=’.$apiKey.’&url_short=’.$short_url;
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, $apiUrl);
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curlObj, CURLOPT_HEADER, 0);
curl_setopt($curlObj, CURLOPT_HTTPHEADER, array(‘Content-type:application/json’));
$response = curl_exec($curlObj);
curl_close($curlObj);
$json = json_decode($response);
return $json[0]->url_long;
}
?>

更多具体使用方法,请参见:http://open.t.sina.com.cn/wiki/index.php/Short_url/expand

原文地址:http://www.biaodianfu.com/sina-shortener-url-api-php.html