Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Facebook Video Upload Error Using Android API 4+

I have this code, after logging in to Facebook, I want to upload selected video to Facebook through Facebook Android SDK v4.13.1,

Problem:

The response looks OK to me, but the video is not showing in the Test User's Timeline.

Code:

public void shareVideoFB(String videoPath, final ProgressDialog pd) {
    AccessToken accessToken = AccessToken.getCurrentAccessToken();
    GraphRequest request = GraphRequest.newPostRequest(accessToken, "https://graph-video.facebook.com/me/videos", null, new GraphRequest.Callback() {
        @Override
        public void onCompleted(GraphResponse response) {
            try {
                if (pd.isShowing())
                    pd.dismiss();
            } catch (Exception e) {
                e.printStackTrace();
            }
            onFBShareVideoCompleted(response);
        }
    });
    Bundle params = request.getParameters();
    try {
        byte[] data = readBytes(videoPath);
        params.putByteArray("video.mp4", data);
        String albumName = "testFBUpload";
        params.putString("title", albumName);
        params.putString("description", " #SomeTag");
        request.setParameters(params);
        request.executeAsync();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

Response 1:

 {Response: responseCode:200, graphObject:{"id":"10150481253673034", "url":"https:\/\/graph-video.facebook.com\/me\/videos"}, error:null}

Response 2:

 {Response: responseCode:200, graphObject:null, error:{HTTPStatus:-1,errorCode:-1,errorType:null, errorMessage:"could not construct request body"}}

EDIT 1

I have created a new test user with several permissions like

  1. public_profile
  2. user_friends,
  3. email,
  4. user_about_me,
  5. user_actions.video,
  6. user_likes,
  7. user_videos,
  8. publish_pages,
  9. publish_actions

and upload the video but still getting the same response as Response 1.

Edit 2

I just noticed that for test users the response is same as Response 1 and with the exact Same ID 10150481253673034

like image 477
Nadeem Iqbal Avatar asked Jun 21 '16 04:06

Nadeem Iqbal


People also ask

Can you post to Facebook via API?

The Graph API is the primary way to get data into and out of the Facebook platform. It's an HTTP-based API that apps can use to programmatically query data, post new stories, manage ads, upload photos, and perform a wide variety of other tasks.

What is Facebook SDK for?

The Facebook SDK is what allows mobile app developers to integrate Facebook within a mobile app. SDK stands for software development kit, and it allows for a website or app to integrate with Facebook seamlessly. Examples of what you can do with Facebook SDK include: Facebook Login functionality. Facebook content ...


2 Answers

You got 2 responses.

Response 1 is from test user.i.e. video is shared successfully. -> So you need to login to facebook using test user's credentials provided from Facebook developer console and check in timeline. If you don't find it in timeline then check it out in profile. You will definitely find it out there.

Sometimes it doest not shows shared post on timeline due to some privacy settings set in that account.

Response 2 is from another account. -> It is failed because unless Facebook approves your app, it will not allow you to share video using another account except test account. So when you application will get approval of publish_actions from Facebook submission process then you can test using different accounts. So it is okay for this case.

Refer https://developers.facebook.com/docs/opengraph/submission-process for submission process.

like image 197
Beena Avatar answered Oct 03 '22 09:10

Beena


In the creation of GraphRequest replace graph path https://graph-video.facebook.com/me/videos by /me/videos.

GraphRequest request = GraphRequest.newPostRequest(accessToken, "/me/videos", null, new GraphRequest.Callback() {
        @Override
        public void onCompleted(GraphResponse response) {
            // your code
        }
    });

Source:

Video Upload with Graph API

Graph API Reference: Video

You can publish videos by using the following edges:

  • /{user-id}/videos
  • /{event-id}/videos
  • /{page-id}/videos
  • /{group-id}/videos
like image 38
Gustavo Morales Avatar answered Oct 03 '22 10:10

Gustavo Morales