I want to share only text via facebook sdk. I researched more time but generally use ShareLinkContent class. Its working but i dont want to add link only post text to user wall via to ShareButton. How i can do?
Code:
ShareLinkContent content = new ShareLinkContent.Builder()
.setContentDescription(Html.fromHtml(shareText).toString())
.setContentUrl(Uri.parse("http://developers.facebook.com/android"))
.build();
ShareApi.share(content, new FacebookCallback<Sharer.Result>() {
#Override
public void onSuccess(Sharer.Result result) {
Toast.makeText(activity, "Success..", Toast.LENGTH_LONG).show();
}
#Override
public void onCancel() {
Toast.makeText(activity, "Cancel..", Toast.LENGTH_LONG).show();
}
#Override
public void onError(FacebookException e) {}
});
shareButton.setFragment(this);
shareButton.setShareContent(content);
FacebookSDK: 4.11.0
Related
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]:
i am not able to get publish_actions permission of facebook sdk4+ i am facing problem and i found there is no proper example available. if any one has the solution do post here. i found that old version solution are shown by everyone but did not found solution for sdk4+ .
LoginManager loginManager = LoginManager.getInstance();
loginManager.logInWithPublishPermissions(this, permissionNeeds);
Log.e("publish_action", "asking_for_permission");
LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>()
{
#Override
public void onSuccess(LoginResult loginResult)
{
if (AccessToken.getCurrentAccessToken().getPermissions().contains("publish_actions"))
{
Log.e("publish_action", "permission_activated");
Bitmap image = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
try {
Log.e("publish_action", "permission_activated_inside_try");
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(image)
.setCaption("A post from Android code")
.build();
SharePhotoContent content = new SharePhotoContent.Builder()
.addPhoto(photo)
.addPhoto(photo)
.addPhoto(photo)
.build();
ShareApi.share(content, new FacebookCallback<Sharer.Result>() {
#Override
public void onSuccess(Sharer.Result result) {
Log.e("successfull", "photo_uploaded");
}
#Override
public void onCancel() {
Log.e("canceled", "photo_uploaded_cancled");
}
#Override
public void onError(FacebookException error) {
Log.e("error", "photo_upload_error");
}
});
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
#Override
public void onCancel() {
System.out.println("onCancel");
Log.e("publish_action", "cancel");
}
#Override
public void onError(FacebookException exception) {
Log.e("publish_action", "error = " + exception.getMessage());
System.out.println("onError");
}
});
I had the same problem, solution was
if (!AccessToken.getCurrentAccessToken().getPermissions().contains("PERMISSION_THAT_YOU_NEED")) {
LoginManager.getInstance().logInWithPublishPermissions((Activity) viewInterface.getContext(), Arrays.asList("PERMISSION_THAT_YOU_NEED"));
return;
You need to return after using logInWithPublishPermissions(), because user may not allow you to use it, but your code will continue to run. And if user provide access to this permission, code will complete successfully next time.
Try this, hope it help to you.
i found this link you must try this url this is a perfect demo for publish_actions permission to facebokk it was helpful for me.
When we post image on facebook by my android app it's post successfully but when we click on that post on Facebook app (on mobile devices) there is a toast appear "There's a problem opening this app." but when open in WEB and click on that posted image it'll redirect to shared link successfully.
I have use this code to share post on facebook.
GraphRequest request = GraphRequest.newPostRequest(AccessToken.getCurrentAccessToken(),
"me/feed", null, new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse response) {
Log.i(TAG, response.toString());
//checkPostStatusAndEnableButton();
}
});
Bundle postParams = request.getParameters();
postParams.putString("link",post_url);
postParams.putString("caption", caption);
request.setParameters(postParams);
request.executeAsync();
Is we have use some other action for url for mobile devices?
Try this on :
private static List<String> PERMISSIONS = Arrays.asList("public_profile","user_photos","user_videos", "email","user_likes","user_posts",
"user_hometown", "user_location","user_about_me","user_birthday",
"user_friends","user_relationship_details");
LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
// App code
Log.i(TAG,"onSuccess registerCallback");
}
#Override
public void onCancel() {
// App code
Log.i(TAG,"onCancel registerCallback");
}
#Override
public void onError(FacebookException exception) {
// App code
Log.i(TAG,"onError registerCallback");
}
});
Then call this share link method :
private void shareLink() {
ShareLinkContent content = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse("https://developers.facebook.com"))
.build();
ShareDialog shareDialog = new ShareDialog(this);
shareDialog.show(content, ShareDialog.Mode.AUTOMATIC);
}
When I try to implement the sharing of links for the app links using the ShareDialog using ShareLinkContent, the image and title are not shown correctly when the actually the post is shared.
String url = "https://fb.me/" + id; //Id is generated by app links hosting api
ShareDialog shareDialog = new ShareDialog(activity);
if (ShareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent.Builder linkContentBuilder = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse(url))
.setContentTitle(contentTitle)
.setContentDescription(contentDescription);
if (imageUrl != null) {
linkContentBuilder.setImageUrl(Uri.parse(imageUrl));
}
ShareLinkContent linkContent = linkContentBuilder.build();
shareDialog.setShouldFailOnDataError(true);
shareDialog.registerCallback(activity.callbackManager,
new FacebookCallback<Sharer.Result>() {
#Override
public void onSuccess(Sharer.Result result) {
Log.d(TAG, "Facebook sharing successful");
}
#Override
public void onCancel() {
Log.d(TAG, "Facebook sharing cancelled");
}
#Override
public void onError(FacebookException e) {
Log.d(TAG, "Facebook sharing error");
Log.d(TAG, e.getMessage());
}
});
shareDialog.show(linkContent);
}
But the sharing looks like below:
Facebook sharing
Can someone help me out?
I want to send my app invites from Facebook.The code I've written is able to send invites but I'm facing two problems.
I don't receive any callback after invitation.
In most of devices Invite dialog has default language Hindi(Click for Screenshot). How can I change the defaults to English?.
PS: I have checked default language in my Facebook developer account app is English.
Any help would be appreciated.
String AppURl = "<My Facebook App URL>";
String previewImageUrl = "<Preview Image URL>";
sCallbackManager = CallbackManager.Factory.create();
AppInviteDialog appInviteDialog = new AppInviteDialog(getActivity());
appInviteDialog.registerCallback(sCallbackManager,
new FacebookCallback<AppInviteDialog.Result>() {
#Override
public void onSuccess(AppInviteDialog.Result result) {
Log.d("Invitation", "Invitation Sent Successfully");
Toast.makeText(getActivity(), "Invitation Sent Successfully", Toast.LENGTH_SHORT).show();
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException e) {
Log.d("Invitation", "Error Occured");
}
});
if (AppInviteDialog.canShow()) {
AppInviteContent content = new AppInviteContent.Builder()
.setApplinkUrl(AppURl)
.setPreviewImageUrl(previewImageUrl)
.build();
appInviteDialog.show(content);
}