获取 HttpResponse (未找到) for Youtube api.



我在应用程序中使用了YouTube api。我正在收到HttpResposeException。我收到以下错误:

我的活动:

searching="https://www.googleapis.com/youtube/v3/search?part=snippet&videoSyndicated=true&type=video&q=len&key=AIzaSyDEWZ7vU_zPi1qgaWEREQEJi2FB3IQCE4g&maxResults=25&pageToken=";
protected Long doInBackground(URL... params) 
    {
        //TODO Auto-generated method stub
        result = UrltoValue.getValuefromUrl(searching);
        return null;
    }

日志猫:

org.apache.http.client.HttpResponseException: Not Found
    at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:71)
    at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:59)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:657)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:627)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:616)

用于将 url 转换为响应的类:

public class UrltoValue {
    static String page="zero";
    public static String getValuefromUrl(String url) throws TimeoutException
    {
        try
        {
            final int TIMEOUT_MILLISEC = 20000;
            HttpParams httpParams = new BasicHttpParams();
            HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MILLISEC);
            HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);
            HttpConnectionParams.setTcpNoDelay(httpParams, true);
            HttpClient httpClient = new DefaultHttpClient(httpParams);
            //DefaultHttpClient httpClient = new DefaultHttpClient();
            URLEncoder.encode(url, "UTF-8");
            HttpPost httpPost = new HttpPost(url);
            ResponseHandler<String> resHandler = new BasicResponseHandler();
            page = httpClient.execute(httpPost, resHandler);
            Log.v("PAGE",page);
            return page;
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            String zero="zero";
            return zero;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            String zero="zero";
            return zero;
        } catch(IllegalArgumentException e) {
            e.printStackTrace();
            String zero="zero";
            return zero;
            //Toast.makeText(context, "Please remove % symbol", Toast.LENGTH_SHORT);
        } catch(Exception e) {
            e.printStackTrace();
            String zero="zero";
            return zero;
        }
    }
}

您指向一个非退出网址。这就是您的堆栈跟踪所说的:

org.apache.http.client.HttpResponseException: Not Found

原因是YouTube网址不接受POST请求。

更改此设置:

HttpPost httpPost = new HttpPost(url);
page = httpClient.execute(httpPost, resHandler);

对此:

HttpGet httpGet = new HttpGet(url);
page = httpClient.execute(httpGet, resHandler);

一切都应该工作。

相关内容

  • 没有找到相关文章

最新更新