0

I am Upload video from my application and get the information of that video (likes,comments)

Problem 1

I have done uploading but when i get video information it throws me error

Error

{"error":{"message":"Cannot specify type in both the path and query parameter.","type":"OAuthException","code":2500}}

I am using Facebook SDK 3.8

Problem 2 When i upload video it Only visible in my account but not visible from other account even though it is public

Code For Upload Video

private void Upload_Video() {

        mDialog = new ProgressDialog(AndroidFacebookConnectActivity.this);
        mDialog.setMessage("Uploding video...");
        mDialog.show();

        String path="/mnt/sdcard/abc/Mirror.mp4";

        if (new File(path).exists()) {
            try {
                Bundle param;
                try {
                    InputStream is = new FileInputStream(path);
                    byte[] data = readBytes(is);
                    param = new Bundle();
                    param.putString("title", "Test 2");
                    param.putString("message", "uploaded");
                    param.putByteArray("video.mov", data);
                    param.putString("contentType", "video/quicktime");
                    mAsyncRunner.request("kmavadhiya/videos", param, "POST",new FBRequestListener(), null);

                    Toast.makeText(getApplicationContext(), "Uploading...", Toast.LENGTH_SHORT).show();
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            Toast.makeText(getApplicationContext(), "No videos found in sdcard ",Toast.LENGTH_SHORT).show();
        }
}

public byte[] readBytes(InputStream inputStream) throws IOException {

        // This dynamically extends to take the bytes you read.
        ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();

        // This is storage overwritten on each iteration with bytes.
        int bufferSize = 1024;
        byte[] buffer = new byte[bufferSize];

        // We need to know how may bytes were read to write them to the byteBuffer.
        int len = 0;
        while ((len = inputStream.read(buffer)) != -1) {
            byteBuffer.write(buffer, 0, len);
        }

        // And then we can return your byte array.
        return byteBuffer.toByteArray();
    }

Upload Request Listner

public class FBRequestListener implements RequestListener {

        @Override
        public void onComplete(String response, Object state) {

            runOnUiThread(new Runnable() { 
                public void run() {
                    Toast.makeText(AndroidFacebookConnectActivity.this, "Upload Video Successfully...",Toast.LENGTH_LONG).show();
                    mDialog.dismiss();
                }
            });
            Log.e("response", response);

            try {
                JSONObject jObject  = new JSONObject(response);
                String Id = (String) jObject.get("id");
                Log.d("Video Id = ",""+Id);

                Bundle param = new Bundle();
                param.putString("type", "uploaded");

                mAsyncRunner.request("kmavadhiya/videos/"+Id, param, "GET",new VideoDataRequestListener(), null);

            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

        @Override
        public void onIOException(IOException e, Object state) {
            e.printStackTrace();
        }

        @Override
        public void onFileNotFoundException(FileNotFoundException e,
                Object state) {
            Log.e("", "onFileNotFoundException");
            e.printStackTrace();

        }

        @Override
        public void onMalformedURLException(MalformedURLException e,
                Object state) {
            Log.e("", "onMalformedURLException");
            e.printStackTrace();
        }

        @Override
        public void onFacebookError(FacebookError e, Object state) {
            Log.e("", "onFacebookError");
            e.printStackTrace();

        }

    }

Video Data Listner

public class VideoDataRequestListener implements RequestListener {

        @Override
        public void onComplete(String response, Object state) {
            // TODO Auto-generated method stub
            Log.e("response", response);

        }

        @Override
        public void onIOException(IOException e, Object state) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onFileNotFoundException(FileNotFoundException e,
                Object state) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onMalformedURLException(MalformedURLException e,
                Object state) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onFacebookError(FacebookError e, Object state) {
            // TODO Auto-generated method stub

        }

    }

If I changed This Line

 mAsyncRunner.request("kmavadhiya/videos/"+Id, param, "GET",new VideoDataRequestListener(), null);

With

 mAsyncRunner.request("kmavadhiya/videos/", param, "GET",new VideoDataRequestListener(), null);

** I got Blank Response**

Reference Link 1

Graph Api Reference Link

Community
  • 1
  • 1
Karan Mavadhiya
  • 1,042
  • 8
  • 23

1 Answers1

0

I Forget To Request Permission At Login time So Its Authentication Error

Add This In Login click

Session session = Session.getActiveSession();
        if (!session.isOpened() && !session.isClosed()) {
            session.openForRead(new Session.OpenRequest(this)
            .setPermissions(Arrays.asList("basic_info","user_about_me","email","video_upload","user_videos"))  // Permission List That You Want To Get
            .setCallback(statusCallback));

        } else {
            Session.openActiveSession(this, true, statusCallback);
        } 

Reference

Permission List

https://developers.facebook.com/docs/facebook-login/access-tokens/

Set Permission Reference

https://developers.facebook.com/docs/android/login-with-facebook#permissions

Karan Mavadhiya
  • 1,042
  • 8
  • 23