0

all the code i saw until now not working with sdk 3.0.1

like this code : Is uploading videos from an SD Card to Facebook possible with the Facebook SDK?

i think this because facebook change util file, but i not sure.

i will glud if someone will share with us (many developer that search for this code) working code (on sdk 3.0.1) that upload successfully mp4 file video to facebook wall from sd cards.

thanks ahead

Community
  • 1
  • 1
idan
  • 1,508
  • 5
  • 29
  • 60
  • post by SirKnigget facebook added a new kind of permission - "upload_video". Even the app that worked never requested that permission, but it somehow uploaded the video regardless of it The way I found this is by noticing that even the onComplete callback has a message, and in that message was the error. Very stupid SDK behavior in my opinion - if I had an error, why call onComplete() and not onFacebookError()? someone have more detail. how to deal with this prob ?? – idan Apr 28 '13 at 13:02

2 Answers2

4

Try this code, it is working:

File file=new File(Environment.getExternalStorageDirectory()+"/testvideo.mp4");
                        try {
                            Request audioRequest = Request.newUploadVideoRequest(session, file, new Request.Callback() {

                                @Override
                                public void onCompleted(Response response) {
                                    // TODO Auto-generated method stub

                                    if(response.getError()==null)
                                    {
                                        Toast.makeText(MainActivity.this, "Video Shared Successfully", Toast.LENGTH_SHORT).show();
                                    }
                                    else
                                    {
                                        Toast.makeText(MainActivity.this, response.getError().getErrorMessage(), Toast.LENGTH_SHORT).show();
                                    }
                                }
                            });
                            audioRequest.executeAsync();
                        } catch (Exception e) {
                            e.printStackTrace();

                        }
Mohit Verma
  • 3,025
  • 1
  • 20
  • 36
0

This is a working to upload video on facebook with sdk 3.0.1 Enjoy...:)

// Check for publish permissions
        List<String> permissions = session.getPermissions();
        if (!permissions.containsAll(PERMISSIONS)) {
            this.requestPublishPermissions(session);
            this.is_return = true;
            return;
        }

        Session session = Session.getActiveSession();
        if (session != null){

            Request.Callback requestCallback= new Request.Callback() {
                public void onCompleted(Response response) {
                    final FacebookRequestError error = response.getError();
                    if(SubmitPost.this.pDialog.isShowing()) {
                        SubmitPost.this.pDialog.dismiss();
                    }
                    if (error != null) {
                        new AlertDialog.Builder(SubmitPost.this)
                            .setTitle("Error")
                            .setMessage(error.getErrorMessage())
                            .setPositiveButton("OK", null)
                            .show();
                        } else {
                        try {
                            GraphObject graphObject = response.getGraphObject();
                            if(graphObject != null) {
                            JSONObject graphResponse = graphObject.getInnerJSONObject();
                            postId = graphResponse.getString("id");
                            SubmitPost.this.write_status.setText("");
                                if(SubmitPost.this.showDialog) {
                                    SubmitPost.this.showDialog = false;
                                    SubmitPost.this.groups_list.setAdapter(SubmitPost.this.adapter);
                                    new AlertDialog.Builder(SubmitPost.this)
                                            .setTitle("Result")
                                            .setMessage("Your status is posted successfully")
                                            .setPositiveButton("OK", null)
                                            .show();
                                }
                            }
                        } catch (JSONException e) {
                            Log.i("TAG","JSON error "+ e.getMessage());

                           Bundle postParams = new Bundle();
                           final RequestBatch requestBatch = new RequestBatch();
                           ParcelFileDescriptor descriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
            postParams.putParcelable(file.getName(), descriptor);
//                      byte[] data = Utility.videoEncode(this.file);
//                      postParams.putByteArray("video", data);
                        for (final String requestId : requestIds) {
                            requestBatch.add(new Request(SubmitPost.this.session, requestId+"/videos", postParams, HttpMethod.POST, requestCallback));
                        }
                    }
                    if (!postParams.containsKey(MIGRATION_BUNDLE_PARAM)) {
                        postParams.putString(MIGRATION_BUNDLE_PARAM, FbSdkVersion.MIGRATION_BUNDLE);
                    }
                }
                requestBatch.executeAsync();
Muhammad Aamir Ali
  • 20,419
  • 10
  • 66
  • 57
  • hi muhammad, thank alot , i try to put your code in click button method but i recieve alot of compailer error with no suggestion, moreover i dont find where to put the video path in it ? – idan Apr 29 '13 at 09:47
  • You will get the video path by override onActivityResult after you select video from gallery – Muhammad Aamir Ali Apr 29 '13 at 10:04