Facebook API add message to SharePhotoContent - android

I want to share a picture on Facebook with a description but I only can post an image without description. How can I add a message/description to the photo?
The code I am using to share:
SharePhoto photo = new SharePhoto.Builder().setBitmap(shareBitmap).build();
ArrayList<SharePhoto> photos = new ArrayList<>();
photos.add(photo);
SharePhotoContent.Builder shareContentBuilder = new SharePhotoContent.Builder();
shareContentBuilder.addPhotos(photos);
SharePhotoContent sharePhotoContent = shareContentBuilder.build();
ShareApi.share(sharePhotoContent, new FacebookCallback<Sharer.Result>() {
#Override
public void onSuccess(Sharer.Result result) {
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException e) {
}
});

Found the solution. I had to add .setCaption("Caption") to the SharePhoto Builder.

Related

Unable to share photo in Facebook

I am taking a photo using an Android phone, and I want to post it in Facebook. My code:
private void SharePhotoFacebook(Bitmap bmp) {
FacebookSdk.sdkInitialize(FaceActivity.this);
// Create a callbackManager to handle the login responses.
callbackManager = CallbackManager.Factory.create();
shareDialog = new ShareDialog(this);
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(bmp)
.build();
if(ShareDialog.canShow(SharePhotoContent.class)){
SharePhotoContent content = new SharePhotoContent.Builder()
.addPhoto(photo)
.build();
shareDialog.show(content);
}
// this part is optional
shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
#Override
public void onSuccess(Sharer.Result result) {
Log.i("David", "Éxito");
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException error) {
Log.i("David", "Error");
}
});
}
But no dialog is showing, and nothing is posted in Facebook. I have implemented this code in the same Activity I take photo (FaceActivity), and is the Activity declared in Facebook Developer page of the app. What is wrong?
I can see like something tries to show (a grey "flash" that appears in the screen) but nothing shows.
EDIT: Im taking photo this way:
makePhoto.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
mCameraSource.takePicture(null, new CameraSource.PictureCallback() {
#Override
public void onPictureTaken(#NonNull byte[] bytes) {
Log.i("David", String.valueOf(bytes.length));
bmp= BitmapFactory.decodeByteArray(bytes,0,bytes.length);
ShowShareDialog();
//SharePhotoFacebook(bmp);
}
});
}
});
I just realized I have this in my debug:
Unsupported get request. Object with ID 'XXXXXXX' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api [extra]:

how to hide app name from Facebook wall post

I have registered an app on my Facebook account, And I am posting Photos from app to Facebook wall post, So It's showing shared via "XYZApp". So I want to remove/hide app name from post.
Check Attachment
I have Used
SharePhoto photo = new SharePhoto.Builder().setBitmap(bm).build();
SharePhotoContent content = new SharePhotoContent.Builder().addPhoto(photo).build();
Setup ContentProvider :
<provider android:authorities="com.facebook.app.FacebookContentProvider{APP_ID}"
android:name="com.facebook.FacebookContentProvider"
android:exported="true"/>
Then add SharePhotoContent Model into content.
public void dialogShare(Bitmap imagePath){
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(imagePath)
.setCaption("StudyTutorial")
.build();
SharePhotoContent content = new SharePhotoContent.Builder()
.addPhoto(photo)
.build();
shareDialog.show(content);
}
Also to share link content use below method :
public static void shareMessageOnFacebook(Activity activity, CallbackManager
callbackManager, String msg) {
LoginManager.getInstance().registerCallback(callbackManager, new
FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
L.e("FacebookError", loginResult.toString());
if (loginResult.getAccessToken() != null) {
ShareLinkContent content = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse("app url"))
.setQuote(msg)
.build();
ShareDialog.show(activity, content);
}
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException exception) {
L.e("FacebookError", exception.getMessage());
}
});
LoginManager.getInstance().logInWithReadPermissions(activity, Arrays.asList("public_profile", "email"));
}

Posting image on Facebook timeline using Facebook SDK for Android

I have an Android app that posts user's status messages to her/his timeline on Facebook (see the code fragment which posts the message below), the problem is that I cannot post any status images like an emoji. I tried sending the image as a byte array (someone suggested that in another post) to no avail, the picture is rejected and if I post the URL of the image, Facebooks inserts the URL instead of the actual image. Is there a way to have the image posted as a real picture? I'm using Facebook SDK 4.11 for Android and Android Studio 2.1. Any hint will be welcome. Thank you
Here is code:
postParams.putString("caption", getResources().getString(R.string.app_name)); // text to post
postParams.putString("message", msg);
postParams.putString("link", "https://www.terra7.net");
if (imgUrl != null) {
//Bitmap bi = BitmapFactory.decodeResource(getResources(), imgId);
//ByteArrayOutputStream baos = new ByteArrayOutputStream();
//bi.compress(Bitmap.CompressFormat.PNG, 100, baos);
//byte[] data = baos.toByteArray();
//postParams.putByteArray("picture", data); // image to post
postParams.putString("picture", imgUrl); // image to post
}
GraphRequest request = new GraphRequest(accessToken, "me/feed", postParams, HttpMethod.POST, new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse response) {
if (response.getError() != null) {
Toast.makeText(MoodFragment.this.getContext(), response.getError().getErrorMessage(), Toast.LENGTH_LONG).show();
}
}
});
request.executeAsync();
Try below code:
public void sharePhotoToFacebook() {
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.pic);
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(bitmap)
.build();
SharePhotoContent content = new SharePhotoContent.Builder()
.addPhoto(photo)
.build();
ShareApi.share(content, new FacebookCallback<Sharer.Result>() {
#Override
public void onSuccess(Sharer.Result result) {
Log.e("onSuccess ", "result " + result);
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException error) {
Log.e("onError ", "error " + error);
}
});
}
For using above code you need publish_actions permission you can use below code for get permission:
public void getPermission() {
List<String> permissionNeeds = Arrays.asList("publish_actions");// - See more at: http://simpledeveloper.com/how-to-share-an-image-on-facebook-in-android/#sthash.v7b5g7GA.dpuf
loginManager = LoginManager.getInstance();
loginManager.logInWithPublishPermissions(this, permissionNeeds);
loginManager.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
sharePhotoToFacebook();
}
#Override
public void onCancel() {
System.out.println("onCancel");
}
#Override
public void onError(FacebookException exception) {
System.out.println("onError");
}
});
// - See more at: http://simpledeveloper.com/how-to-share-an-image-on-facebook-in-android/#sthash.v7b5g7GA.dpuf
}

Post On Facebook Wall With Android

how to share post on wall from facebook sdk 4.10.0 in android?
List<String> permissionNeeds = Arrays.asList("publish_actions");
manager = LoginManager.getInstance();
manager.logInWithPublishPermissions(this, permissionNeeds);
manager.registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
}
#Override
public void onCancel() {
System.out.println("onCancel");
}
#Override
public void onError(FacebookException exception) {
System.out.println("onError");
}
});
I'm Working With This Code...
use this code.
shareDialog = new ShareDialog(this);
callbackManager = CallbackManager.Factory.create();
shareDialog.registerCallback(callbackManager, new
FacebookCallback<Sharer.Result>() {
#Override
public void onSuccess(Sharer.Result result) {
Toast.makeText(getApplicationContext(),"Success",Toast.LENGTH_SHORT).show();
}
#Override
public void onCancel() {
Toast.makeText(getApplicationContext(),"Not Success",Toast.LENGTH_SHORT).show();
}
#Override
public void onError(FacebookException error) {}
});
if (ShareDialog.canShow(ShareLinkContent.class)) {
//Post Link with Detail On Wall....
/* ShareLinkContent content = new ShareLinkContent.Builder()
.setContentTitle("Hello Facebook")
.setContentDescription("The 'Hello Facebook' sample showcases simple Facebook integration")
.setContentUrl(Uri.parse("http://developers.facebook.com/android"))
.build();*/
//Post Image on Wall...........
Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.naturals1);
SharePhoto photo = new SharePhoto.Builder().setBitmap(image).build();
SharePhotoContent content = new SharePhotoContent.Builder()
.addPhoto(photo)
.build();
shareDialog.show(content);
}

Not able to tag friends on facebook when share photo using android:facebook-sdk:4.1.0

I share link on facebook with taggable friends it work fine and when share photos with taggable friends its not work.Display only photos on facebook without tagged friends.
Code that i used to share photos on facebook.
ArrayList<String> friendsIds = new ArrayList<>();
List<SharePhoto> photoList = new ArrayList<>();
Bitmap image1 = BitmapFactory.decodeResource(getResources(), R.drawable.offer_1);
SharePhoto photo1 = new SharePhoto.Builder()
.setBitmap(image1)
.setCaption(mRestaurantName)
.build();
Bitmap image2 = BitmapFactory.decodeResource(getResources(), R.drawable.offer_placeholder_image);
SharePhoto photo2 = new SharePhoto.Builder()
.setCaption(mRestaurantName + " Testing ")
.setBitmap(image2)
.build();
photoList.add(photo1);
photoList.add(photo2);
ShareContent content = new SharePhotoContent.Builder()
.addPhotos(photoList)
.setPeopleIds(friendsIds)
.build();
ShareApi.share(content, new FacebookCallback<Sharer.Result>() {
#Override
public void onSuccess(Sharer.Result result) {
if (result != null)
showToast(getString(R.string.successfully_post_on_facebook));
}
#Override
public void onCancel() {
showToast(getString(R.string.you_have_cancelled_th_request));
}
#Override
public void onError(FacebookException e) {
showToast(e.getMessage());
}
});

Categories

Resources