Unable to share a video to Facebook - android

We have a sharing facility in our App where we facilitate sharing images/videos to Facebook. We are using Facebook Android SDK 4.27.0 for Facebook login and sharing.
Now, the images/videos are present on our own server(i.e, the media is not present on my device) and we intend to share these directly with Facebook using a Graph call. Here is the working implementation of photo sharing:
Bundle postParams = new Bundle();
postParams.putString("name", itemdesc);
postParams.putString("url", itemurl);
new GraphRequestAsyncTask(new GraphRequest(
AccessToken.getCurrentAccessToken(), "me/photos", postParams, HttpMethod.POST,
new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse response) {
FacebookRequestError error = response.getError();
// Do something with the error
}
})).execute();
But, a similar implementation for videos is not working:
Bundle postParams = new Bundle();
postParams.putString("name", itemdesc);
postParams.putString("url", itemurl);
new GraphRequestAsyncTask(new GraphRequest(
AccessToken.getCurrentAccessToken(), "https://graph-video.facebook.com/me/videos", postParams, HttpMethod.POST,
new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse response) {
FacebookRequestError error = response.getError();
}
})).execute();
For the endpoint, "https://graph-video.facebook.com/me/videos", I get the following response on sharing with a test user:
{Response: responseCode: 200, graphObject: {"id":"10150481253673034","url":"https:\/\/graph-video.facebook.com\/me\/videos"}, error: null}
But, the video doesn't show on the test user's timeline.
And for the endpoint, "me/videos", I get the response,
{HttpStatus: 400, errorCode: 390, errorType: OAuthException, errorMessage: There was a problem uploading your video file. Please try again.}
So, how do I go about sharing a video to Facebook?

Related

Android Facebook Album cover photo

I am trying to fetch Cover Photo of an album using Graph API.
Here is my code:
Bundle params = new Bundle();
params.putString("type", "thumbnail");
/* make the API call */
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/" + albumID + "/picture",
params,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
Log.v("TAG", "Facebook Photos response: " + response);
}
}
).executeAsync();
Using above code, I am getting below response:
{Response: responseCode: 200, graphObject: {"FACEBOOK_NON_JSON_RESULT":"����\u0000\u0010JFIF\u0000\u0001\u0002\u0000\u0000\u0001\u0000\u0001\u0000\u0000��\u0000�Photoshop"}, error: null}
Can anyone help me what is wrong with my request and how I can get a cover photo of an album?
Thanks in advance.
After googling, I found a solution and its working fine for me.
I have changed Bundle parameters as below:
Bundle params = new Bundle();
params.putString("type", "thumbnail");
params.putBoolean("redirect", false);
Rest of code as it.
After changing, I am getting proper response same as I get in Graph API browser:
{Response: responseCode: 200, graphObject: {"data":{"is_silhouette":false,"url":"https:\/\/scontent.xx.fbcdn.net\/v\/t1.0-0\/s180x540\/13782019_1735895746671060_1058868038400371031_n.jpg?_nc_cat=0&oh=506c19df47791a4b7fcfc362eeed0676&oe=5B92AA68"}}, error: null}

Android facebook upload photo on a feed page

Hi guys I am trying to upload a photo to a page on Facebook. This is the page i am trying to post the photo https://www.facebook.com/manegedagen/.
I have been using the following code :
public static void postImageOnWall(Bitmap pBitmap) {
Bundle bundle =new Bundle();
bundle.putString("method", "photos.upload");
bundle.putString("picture","http://www.demos.com/LangGuage/medal_1.png");
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/2091172661108128/feed",
null,
HttpMethod.POST,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
Log.e("", "");
}
}
).executeAsync();
}
But i am getting an error message: OAuthException: errorMessage: Invalid parameters. I would really appreciate if i can get any guide or help.
Try with parameters not as null
see the selected answer from this reference:
https://stackoverflow.com/a/29770773/6011938

Test publish permissions for Facebook app

I want to test the publish permissions for my facebook app, however when using the graph api(s) to either like or comment, I get an error from the facebook server.
The code being used to post a like is as below:
Bundle params = new Bundle();
params.putString("url", "http://www.imdb.com/title/tt2015381/");
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/" + facebookObjectId + "/likes",
params,
HttpMethod.POST,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Log.i(TAG, "FACEBOOK GRAPH RESPONSE FOR POSTING LIKE: " + response);
}
}
).executeAsync();
The corresponding error that is being generated is:
FACEBOOK GRAPH RESPONSE FOR POSTING LIKE: {Response: responseCode: 403, graphObject: null, error: {HttpStatus: 403, errorCode: 200, errorType: OAuthException, errorMessage: (#200) App does not have permission to make this call}}
essentially suggesting that App does not have permission to make this call
To post custom like:
Bundle params = new Bundle();
params.putString("object", linkURL);
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/" + Profile.getCurrentProfile().getId() + "/og.likes",
params,
HttpMethod.POST,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Log.i(TAG, "FACEBOOK GRAPH RESPONSE FOR POSTING LIKE: " + response);
}
}
).executeAsync();
To delete custom like:
Bundle params = new Bundle();
params.putString("object", linkURL);
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/" + likeActionInstanceId,
params,
HttpMethod.DELETE,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Log.i(TAG, "FACEBOOK GRAPH RESPONSE FOR DELETING LIKE: " + response);
}
}
).executeAsync();
Here the likeActionInstanceId is the id received after submitting the like successfully.
NOTE: Comments can't be added as of now from your own app. Comment Mirroring is in beta phase at Facebook.

Post image from android to facebook page

I have successfully post a feed in facebook page form the graph api.
try {
resObj.put("message","feed from android");
//resObj.put("object_attachment",bitmap);
} catch (JSONException e) {
e.printStackTrace();
}
GraphRequest request = GraphRequest.newPostRequest(
AccessToken.getCurrentAccessToken(),"363453267193844/photos",resObj,
new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse graphResponse) {
Log.i(TAG,"post page response::"+graphResponse);
}
}
);
request.executeAsync();
But, I'm unable to post image into facebook page. The problem is I'm unable to find the key for image attachment in Json data posted in Graph Api.
The failed response from facebook is
{Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 324, errorType: OAuthException, errorMessage: (#324) Requires upload file}}
Finally, finally, I was able to post an image into facebook page. This is how I did to post an photo.
Bundle bundle=new Bundle();
bundle.putByteArray("object_attachment",byteArray);// object attachment must be either byteArray or bitmap image
bundle.putString("message","some message here");
GraphRequest graphRequest=new GraphRequest(AccessToken.getCurrentAccessToken(),
"{page_id}/photos",
bundle,
HttpMethod.POST,
new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse graphResponse) {
Log.i("post page response::" + graphResponse);
}
);
graphRequest.executeAsync();
1.) Make sure you a page access token with publish_pages permission that can be used to publish new photos.
2.) From the docs . Note that you dont have a "/" before pageid in your call.
There are two separate ways of publishing photos to Facebook:
1: Attach the photo as multipart/form-data. The name of the object
doesn't matter, but historically people have used source as the
parameter name for the photo. How this works depends on the SDK you
happen to be using to do the post.
2: Use a photo that is already on the internet by publishing using the
url parameter:
Bundle params = new Bundle();
params.putString("url", "{image-url}");
/* make the API call */
new Request(
session,
"/{page-id}/photos",
params,
HttpMethod.POST,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
}
}
).executeAsync();
There is no way to publish more then one photo in the same graph API
call.
3.) Example ==>
Try it like this i.e post byteArrayStream of your photo
postParams = new Bundle();
postParams.putString("message", "feed from android");
postParams.putBoolean("published",true);
String pageID = "363453267193844";
//Post to the page as the page user
ByteArrayOutputStream stream = new ByteArrayOutputStream();
<YOURBITMAPPHOTOHANDLE>.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
postParams.putByteArray("source", byteArray);
postParams.putString("access_token", "your_page_access_token");
/* make the API call */
new Request(
sessionInstance,
"/" + pageID + "/photos",
postParams,
HttpMethod.POST,
new Request.Callback() {
public void onCompleted(Response response) {
//An error occurred during posting to facebook
FacebookRequestError error = response.getError();
if (error != null) {
isPostingError = true;
postingErrorMessage = error.getErrorUserMessage();
} else {
isPostingError = false;
}
}
}
). executeAsync();

Unable to execute "Facebook Like" from within Android application

From within my Android application, i am trying to implement a simple "Like Button" functionality.
We have already executed Facebook log in from the same app.
We have also created an Open Graph Like action & a Link object as well on our App's Dashboard.
This is the code that we are using to publish the like.
public static void likeFacebookPage(Context context,String pageUrl)
{
Bundle params = new Bundle();
params.putString("object",pageUrl);
Request request = new Request(
Session.getActiveSession(),
"me/og.likes",
params,
HttpMethod.POST
);
Response response = request.executeAndWait();
// handle the response
}
In the pageUrl parameter, we have:
http://www.facebook.com/<object_id>
"object_id" is the Id of the Link Object that we have created in Open Graph.
After executing the above method, the response object received as follows:
{Response: responseCode: 200, graphObject: null, error: {HttpStatus: -1, errorCode: -1, errorType: null, errorMessage: null}, isFromCache:false}
But the Like count is not getting updated, leading us to believe that this process is not working.
We have also included the permissions "publish_actions" & "user_likes" in our code as well as on the App Dashboard.
Kindly help us with configuring this functionality.
Thanks in advance.
As described here https://developers.facebook.com/docs/reference/api/publishing/ you publish a like to an object like so with the publish_actions and publish_stream permissions:
Bundle postParams = new Bundle();
Request request = new Request(Session.getActiveSession(),
FB_OBJECT_ID+"/likes", postParams, HttpMethod.POST, new Callback() {
#Override
public void onCompleted(Response response) {
}
});
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
Where your FB_OBJECT_ID is simply the ID of the object. I.e if you want to like a photo, FB_OBJECT_ID would be the pid. For an album, FB_OBJECT_ID would be the aid.

Categories

Resources