0

https://player.vimeo.com/video/136004191/config trying to fetch real URL from vimeo while i m getting error :

response code:405
07-26 11:42:46.236 22054-22183/com.sample.samplevideoview W/System.err: java.io.FileNotFoundException: https://player.vimeo.com/video/136004191/config
07-26 11:42:46.236 22054-22183/com.sample.samplevideoview W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:238)
07-26 11:42:46.236 22054-22183/com.sample.samplevideoview W/System.err:     at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
07-26 11:42:46.236 22054-22183/com.sample.samplevideoview W/System.err:     at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java)
07-26 11:42:46.237 22054-22183/com.sample.samplevideoview W/System.err:     at com.sample.samplevideoview.AsyncHttpClient$AsyncDataRequestHideDialog.doInBackground(AsyncHttpClient.java:353)
07-26 11:42:46.237 22054-22183/com.sample.samplevideoview W/System.err:     at com.sample.samplevideoview.AsyncHttpClient$AsyncDataRequestHideDialog.doInBackground(AsyncHttpClient.java:287)
07-26 11:42:46.237 22054-22183/com.sample.samplevideoview W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:295)
07-26 11:42:46.237 22054-22183/com.sample.samplevideoview W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
07-26 11:42:46.237 22054-22183/com.sample.samplevideoview W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
07-26 11:42:46.237 22054-22183/com.sample.samplevideoview W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
07-26 11:42:46.237 22054-22183/com.sample.samplevideoview W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
07-26 11:42:46.237 22054-22183/com.sample.samplevideoview W/System.err:     at java.lang.Thread.run(Thread.java:818)
07-26 11:42:46.281 22054-22054/com.sample.samplevideoview E/MainActivity: Must implement the interface java.lang.NullPointerException: Attempt to invoke virtual method 'com.sample.samplevideoview.Request com.sample.samplevideoview.VimeoResponse.getRequest()' on a null object reference

here is the code:

    private void getRealUrl(String videoId)
        {
            AsyncHttpClient mAsyncHttpClient = new AsyncHttpClient();
            HashMap<String, String> params = new HashMap<>();
            String url = "https://player.vimeo.com/video/" + videoId + "/config";

            mAsyncHttpClient.postWithStringData(MainActivity.this, TAG,
                    url, StringConstants.METHOD_GET, params,false,
                    new AsyncHttpClient.AsyncHttpResponseCallBack() {
                        @Override
                        public void onResponse(String response) {
                            Gson gson = new GsonBuilder().create();
                            VimeoResponse movie = gson.fromJson(response, VimeoResponse.class);

                        }
                    }
        );
        }
public class AsyncHttpClient {

    public interface AsyncHttpResponseCallBack {
        void onResponse(String response);
    }

    private Vector<Object> params;
    private static final String UTF_ENCODING = "UTF-8";

    private static final int CONTEXT_INDEX = 0;
    private static final int TAG_INDEX = 1;
    private static final int URL_INDEX = 2;
    private static final int PARAMS_STRING_INDEX = 3;
    private static final int RESPONSE_CALLBACK_INDEX = 4;
    private static final int REQUEST_METHOD_INDEX = 5;
    private static final int SHOW_PROGRESS_DIALOG_INDEX = 6;
public void postWithStringData(Context context, String TAG, String url, String method,
                                   HashMap<String, String> hashMapParams, boolean showDialog,
                                   AsyncHttpResponseCallBack asyncHttpResponseCallBack) {
        if (Utilities.isConnected(context)) {
            try {
                params = new Vector<>();
                params.insertElementAt(context, CONTEXT_INDEX);
                params.insertElementAt(TAG, TAG_INDEX);
                params.insertElementAt(url, URL_INDEX);
                params.insertElementAt(getPostDataString(hashMapParams), PARAMS_STRING_INDEX);
                params.insertElementAt(asyncHttpResponseCallBack, RESPONSE_CALLBACK_INDEX);
                params.insertElementAt(method, REQUEST_METHOD_INDEX);
                new AsyncDataRequestHideDialog(context).execute(params);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
    }
private class AsyncDataRequestHideDialog extends AsyncTask<Vector<Object>, Void, String> {

        AlertDialog mAlert;
        String TAG, url;
        String paramsString;
        AsyncHttpResponseCallBack asyncHttpResponseCallBack;
        Context context;

        String method;
        public AsyncDataRequestHideDialog(Context context) {
            // TODO Auto-generated constructor stub
            this.context = context;
        }

        @Override
        protected String doInBackground(Vector<Object>... params) {
            Vector<Object> requestParams = params[0];
            TAG = (String) requestParams.get(TAG_INDEX);
            url = (String) requestParams.get(URL_INDEX);
            paramsString = (String) requestParams.get(PARAMS_STRING_INDEX);
            asyncHttpResponseCallBack = (AsyncHttpResponseCallBack) requestParams.get(RESPONSE_CALLBACK_INDEX);
            method = (String) requestParams.get(REQUEST_METHOD_INDEX);

            String result = "";
            URL requestURL;
            StringBuffer response;

            try {
                requestURL = new URL(url);
                HttpURLConnection conn = (HttpURLConnection) requestURL.openConnection();
                conn.setReadTimeout(StringConstants.READ_TIMEOUT);
                conn.setConnectTimeout(StringConstants.CONNECTION_TIMEOUT);
                conn.setRequestMethod(method);
                conn.setDoInput(true);
                conn.setDoOutput(true);
                OutputStream os = conn.getOutputStream();
                BufferedWriter writer = new BufferedWriter(
                        new OutputStreamWriter(os, UTF_ENCODING));
                writer.write(paramsString);
                writer.flush();
                writer.close();
                os.close();
                String line;
                response = new StringBuffer();
                Log.d(TAG,"response code:"+conn.getResponseCode());
                BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                while ((line = br.readLine()) != null) {
                    response.append(line);
                }
                result = response.toString();
            } catch (SocketTimeoutException e1) {
                e1.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();

            } finally {
                Log.d(TAG, result);
                return result;
            }
        }

        // Overriding onPreExecute to initialize and show progress dialog
        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();

        }
        @Override
        protected void onPostExecute(String result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);

            // If result is not null
            if (result != null) {
                try {
                    // Making a log just to make sure of data.
                    Log.e(TAG, result);
                    asyncHttpResponseCallBack.onResponse(result);
                } catch (Exception e) {
                    Log.e(TAG, "Must implement the interface " + e.toString());
                }
            } else {
                mAlert = Utilities.createAlertDialog(context, "Error",
                        StringConstants.DATA_ERROR);
            }
        }
    }

while i m getting response code 405 ? what is the issue ? the same url in mobile and desktop browser responding me.

Erum
  • 790
  • 3
  • 14
  • 36

2 Answers2

1

I would highly recommend using the official vimeo-networking Java/Android library for talking to the Vimeo API.

The library will take care of all of the networking logic (so you won't need to HttpURLConnection boilerplate) and it also offers calls to get videos by URI.

Here is how to request a single video. It essentially looks like:

String uri = ...;// the video uri; if you have a Video, this is video.uri
VimeoClient.getInstance().fetchNetworkContent(uri, new ModelCallback<Video>(Video.class) {
     @Override
     public void success(Video video) {
          // use the video
     }

     @Override
     public void failure(VimeoError error) {
          // voice the error
     }
});

Then if you own the video, you can access any information you want right off of the Video object in the library. Information like video.files which returns a VideoFile which gives you access to the links you'd want.

Kyle Venn
  • 4,597
  • 27
  • 41
  • Then if you own the video, you can access any information i dnt have my own account of vimeo and dnt have any videos on my own setup .Moreover i just have videos link that is youtube , dailymotion , vimeo so i just have to play vimeo videos using its own sdk because i m not getting real url from my api response – Erum Jul 28 '16 at 06:38
  • Using the API, you can only access the `files` object on a `Video` if you're the person who uploaded that video (with a PRO account). On web, there is an "embedded player" which lets you play any video but as of right now there is no embedded player option on Android. Please refer to [this link](http://stackoverflow.com/questions/9030524/auto-playing-vimeo-videos-in-android-webview) which covers getting a player on Android using a `WebView` to play the web embedded player. – Kyle Venn Jul 28 '16 at 12:51
0

Your code seems problematic, since for simple GET string request OutputStream and Buffer Classes were causing exception. Try this simple code. Working fine on my side.

 @Override
            protected String doInBackground(Vector<Object>... params) {

                String result = "";
                url = "https://player.vimeo.com/video/136004191/config";

                try {

                    URL obj = new URL(url);

                    HttpURLConnection con = (HttpURLConnection) obj.openConnection();

                    // optional default is GET
                    con.setRequestMethod("GET");
                    BufferedReader in = new BufferedReader(
                            new InputStreamReader(con.getInputStream()));
                    String inputLine;
                    StringBuffer response = new StringBuffer();

                    while ((inputLine = in.readLine()) != null) {
                        response.append(inputLine);
                    }
                    in.close();

                    //print result
                    System.out.println(response.toString());

                    result = response.toString();
                } catch (SocketTimeoutException e1) {
                    e1.printStackTrace();
                } catch (Exception e) {
                    e.printStackTrace();

                } finally {
                    Log.d(TAG, result);
                    return result;
                }
            }
NightFury
  • 13,436
  • 6
  • 71
  • 120