php代碼: 獲取新浪微博的Tiny網址鏈接

字號+ 編輯: 国内TP粉 修訂: 种花家 來源: 2023-10-19 我要說兩句(0)

一套代碼解決問題。(可能有點老,需要大佬後期測試)

这套代码也是根据网友披露出来的demo, 新浪微博如果有更新,可能地址要发生改变,大佬可以直接拷贝测试看能不能用。

代码如下:

// http://open.weibo.com/wiki/2/short_url/shorten

function GetTurl($url = '')
{    set_time_limit(0);
    // $tApi="https://api.weibo.com/2/short_url/shorten.json?access_token=[你的token]&url_long=";
    $tApi="https://api.weibo.com/2/short_url/shorten.json?source=[你的appkey]&url_long=";
    $tApi=$tApi.urlencode($url);
    $ret = file_get_contents($tApi);
    $ret = json_decode($ret,true);
    if($ret['error']) return $url;
    if(is_array($ret['urls'])) {
        $r= $ret['urls'][0]['url_short'];
        return $r;
    }
    return $url;
}


閲完此文,您的感想如何?
  • 有用

    1

  • 沒用

    0

  • 開心

    1

  • 憤怒

    0

  • 可憐

    0

1.如文章侵犯了您的版權,請發郵件通知本站,該文章將在24小時内刪除;
2.本站標注原創的文章,轉發時煩請注明來源;
3.交流群: 2702237 13835667

相關課文
  • mac開發接入微信公衆號接口返回報錯 cURL error 56: SSLRead() return error -9806

  • PHP的換行符是什麽

  • pecl安裝程序時報錯Array and string offset access syntax with curly braces is no longer supported

  • 由於商家傳入的H5交易參數有誤,該筆交易暫時無法完成,請聯繫商家解決

我要說說
網上賓友點評