Post On Facebook Wall With Android - 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);
}

Related

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"));
}

Post_Id ShareDialog always return null in Android

Event show dialog :
ShareDialog shareDialog = new ShareDialog(this);
shareDialog.registerCallback(viewModel.callbackManager, viewModel.facebookCallbackShare, REQUEST_SHARE);
if (ShareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent shareLinkContent = new ShareLinkContent.Builder()
.setContentDescription(description)
.setContentTitle("title")
.setQuote(description)
.setContentUrl(Uri.parse(link))
.build();
shareDialog.show(shareLinkContent, ShareDialog.Mode.FEED);
}
}
And Facebook Callback;
I'm using FacebookCallback with Sharer.Result to listen data callback:
public FacebookCallback<Sharer.Result> facebookCallbackShare = new FacebookCallback<Sharer.Result>() {
#Override
public void onSuccess(Sharer.Result result) {
JSONObject data = new JSONObject();
try {
data.put("post_id", (result.getPostId() != null) ? result.getPostId() : "postID_dang_null");
} catch (JSONException e) {
e.printStackTrace();
}
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException error) {
}
};
Code dont show any bug, but also this not return postID . I need postid to update this to api server.

Android Facebook Share ,Description not showing

I am using facebook sdk for sharing on facebook.
My code is below,it's working fine.But when i want to change the content url to Application playstore link then content description is not showing into facebook.
Is there any solution or i am making stupid mistake ?
if (ShareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle(AppConstant.RESTURENT_NAME)
.setContentDescription("Hi,You should check out Bangkok Eatery.")
.setContentUrl(Uri.parse("http://developers.facebook.com/android"))
.build();
shareDialog.show(linkContent);
}
ShareDialog shareDialog = new ShareDialog(this);
CallbackManager callbackManager = CallbackManager.Factory.create();
shareDialog.registerCallback(callbackManager, new
FacebookCallback<Sharer.Result>() {
#Override
public void onSuccess(Sharer.Result result) {
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException error) {
}
});
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle(getString(R.string.app_name))
.setContentDescription("")
.setContentUrl(Uri.parse("your link"))
.build();
shareDialog.show(linkContent);
FacebookSdk initialize in onCreate method
CallbackManager callbackManager;
ShareDialog shareDialog;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
shareDialog = new ShareDialog(this);
// this part is optional
shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() { ... });
}
if (ShareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle(AppConstant.RESTURENT_NAME)
.setContentDescription("Hi,You should check out Bangkok Eatery.")
.setContentUrl(Uri.parse("http://developers.facebook.com/android"))
.build();
shareDialog.show(linkContent);
}

have publish_actions approved but facebook post not public

My android application have publish_actions submission were approved but when I post photo on facebook via my application It's not public post because my friend on facebook cannot see this that post.
final String hashTagPost = hashtag;
callbackManager = CallbackManager.Factory.create();
List<String> permissionNeeds = Arrays.asList("publish_actions"); //I added publish_actions
loginManager = LoginManager.getInstance();
loginManager.logInWithPublishPermissions(this, permissionNeeds);
loginManager.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(bitmap)
.setCaption(txtCaption.getText().toString() + " #EventPocket " + hashTagPost)
.build();
SharePhotoContent content = new SharePhotoContent.Builder()
.addPhoto(photo)
.build();
ShareApi.share(content, null);
Toast.makeText(PhotoActivity.this, "Post Success", Toast.LENGTH_SHORT).show();
finish();
dialog.dismiss();
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException e) {
}
}
This a part of my application.
What I do it more?

Facebook API add message to SharePhotoContent

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.

Categories

Resources