一、之前的调用方式

这种方式用了大约有一年时间,之前没有问题,但是2019-8-28号突然不行了,可能是由于微博对该接口的调用做了限制。不允许通过传递source参数的方式进行请求

该接口微博API文档

  /**
     * source去新浪微博申请App Key
     * @param long_url
     * @return
     */
    @Deprecated
    public static String getShortUrl2(String long_url) {
        String result = HttpUtils.get(
                "https://api.weibo.com/2/short_url/shorten.json?source="+app_key+"&url_long=" + long_url);

        JSONObject jsonObject = JSON.parseObject(result);

        JSONObject urls = jsonObject.getJSONArray("urls").getJSONObject(0);
        String url_short = urls.getString("url_short");
        return url_short;
    }

 

二、修改后的调用方式

该接口微博API文档地址

  /**
     * source去新浪微博申请App Key
     * @param long_url
     * @return
     */
    public static String getShortUrl(String long_url) {
        String result = HttpUtils.get(
                "https://api.t.sina.com.cn/short_url/shorten.json?source="+app_key+"&url_long=" + long_url);

        JSONObject jsonObject = JSON.parseArray(result).getJSONObject(0);

        String url_short = jsonObject.getString("url_short");
        return url_short;
    

 

转载于:https://www.cnblogs.com/756623607-zhang/p/11441190.html

原文链接:https://blog.csdn.net/weixin_30342827/article/details/101143396

本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。

本博客所有文章如无特别注明均为原创。
复制或转载请以超链接形式注明转自起风了,原文地址《【异常】微博生成短链异常{“request”:”/2/short_url/shorten.json”,”error_code”:”10014″,”error”:”Insufficient app pe…
   

还没有人抢沙发呢~