i have a big problem for sharing text via ShareDialog. It seems i can only share predefined links,descriptions... but not text. Is there any other way to share text of Facebook from my Android app.
My code is:
FacebookDialog shareDialog = createShareDialogBuilderForLink().build();
private FacebookDialog.ShareDialogBuilder createShareDialogBuilderForLink() {
return new FacebookDialog.ShareDialogBuilder(this)
.setCaption("Here Comes the Boom!!!!")
.setName("Hello Facebook")
.setDescription("Here is my description")
.setLink("http://developers.facebook.com/android");
}
It's impossible, you have to use the Facebook api to do this.
More informations here: https://stackoverflow.com/a/22123047/2065418
Code for Facebook sharing text/link
public void post(String post_text) {
Bundle postParam = new Bundle();
Request.Callback callback = new Request.Callback() {
#Override
public void onCompleted(Response response) {
// shareDialog.dismiss();
// showPublishResult("Photo Post", response.getGraphObject(),
// response.getError());
}
};
Session session = createSession();
postParam.putString("name", post_text);
postParam.putString("link", "https://developers.facebook.com/android");
Request request = new Request(session, "me/feed", postParam,
HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
Related
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);
}
I have this simple problem made complicated because of FB. I try to share from android a link and image using facebook sdk.
Did anyone played with ShareOpenGraphObject, ShareOpenGraphAction and ShareOpenGraphContent before, facebook documentation just sucks, no examples at all. I am waiting for examples.
Thanks
let s post some code then:
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
.putString("og:type", "books.book")
.putString("og:title", "A Game of Thrones")
.putString("og:description", "In the frozen wastes to the north of Winterfell, sinister and supernatural forces are mustering.")
.putString("books:isbn", "0-553-57340-3")
.build();
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("books.reads")
.putObject("book", object)
.putPhoto("image", photo)
.build();
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("book")
.setAction(action)
.build();
shareDialog.show(this, content);
idea is that i don t want to use a book, i just want so share a image a link and a message...how the f i do that? facebook sdk sucks
Its Simple, You can find many examples as well as in Facebook SDK you can find sample for the same...
Bundle postParams = new Bundle();
postParams.putString("link", url);
postParams.putString("picture", imgUrl);
Request request = new Request(session, "me/feed", postParams,
HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
I think by using facebook sdk 4.0, you can share contents via share api.
eg:
public void share()
{
ShareLinkContent content=new ShareLinkContent.Builder()
.setContentTitle("Your Title")
.setContentUrl(Uri.parse("website link"))
.setImageUrl(Uri.parse("Image url"))
.build();
ShareApi.share(content, new FacebookCallback<Sharer.Result>(){
#Override
public void onSuccess(Result result){
}
#Override
public void onCancel(){
}
#Override
public void onError(FacebookException error){
}
});
}
For sharing link and image , ShareDialog
Provides functionality to share content via the Facebook Share Dialog and
ShareLinkContent
Describes link content to be shared.
is one method without the Open Graph method.
Snippet is like
private ShareDialog shareDialog;
private boolean canPresentShareDialogWith;
shareDialog = new ShareDialog(this);
canPresentShareDialogWith = ShareDialog.canShow(ShareLinkContent.class);
ShareLinkContent linkContent = new ShareLinkContent.Builder().setContentTitle("Shared from " + "<APP NAME>")
.setContentDescription(
"Question:" + data.getQuestion() + "\n"
// + "Asked by : "
// + data.getName() + "\n"
)
.setContentUrl(
Uri.parse("<Website url>"))
.setImageUrl(Uri.parse(data.getPicUploadPath()))
.build();
if (canPresentShareDialogWith) {
shareDialog.show(linkContent);
} else if (profile != null && hasPublishPermission()) {
ShareApi.share(linkContent, shareCallback);
}
private FacebookCallback<Sharer.Result> shareCallback = new FacebookCallback<Sharer.Result>() {
#Override
public void onCancel() {
Log.d("HelloFacebook", "Canceled");
}
#Override
public void onError(FacebookException error) {
Log.d("HelloFacebook", String.format("Error: %s", error.toString()));
String title = getString(R.string.error);
String alertMessage = error.getMessage();
showResult(title, alertMessage);
}
#Override
public void onSuccess(Sharer.Result result) {
Log.d("HelloFacebook", "Success!");
if (result.getPostId() != null) {
String title = getString(R.string.success);
String id = result.getPostId();
String alertMessage = getString(
R.string.successfully_posted_post, id);
showResult(title, alertMessage);
}
}
private void showResult(String title, String alertMessage) {
new AlertDialog.Builder(NewsfeedMain.this).setTitle(title)
.setMessage(alertMessage)
.setPositiveButton(R.string.ok, null).show();
}
};
The method here is sharing a link with the respective web url to load , when clicked from FB feed and the image shared is via a link by the native facebook android app or fallback to sdk share dialog is no facebook app is persent.
Session session = Session.getActiveSession();
Request.Callback callback = new Request.Callback() {
#Override
public void onCompleted(Response response) {
// response should have the likes
Toast.makeText(getApplicationContext(), response.toString(), Toast.LENGTH_LONG).show();
}
};
Request request = new Request(session, "me/likes", null, HttpMethod.GET, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();``
I am trying to get facebook likes using facebook sdk using this code But it is not working.Is there any other way to get it?
Here you can try this code link
it will help you out
I am trying to post a feed on Facebook wall without opening a dialogue box using Facebook Android SDK. I tried to find a way but couldn't find. Can anyone tell em how to post to wall in background without opening a dialogue.
I tried using the below code
public static void PublishToFeedInBackground()
{
final Bundle _postParameter = new Bundle();
_postParameter.putString("name", name);
_postParameter.putString("link", link);
_postParameter.putString("picture", link_to_image);
_postParameter.putString("caption", caption);
_postParameter.putString("description", description);
final List<String> PERMISSIONS = Arrays.asList("publish_actions");
if (Session.getActiveSession() != null)
{
// Check for publish permissions
List<String> _permissions = Session.getActiveSession().getPermissions();
if (!isSubsetOf(PERMISSIONS, _permissions))
{
NewPermissionsRequest reauthRequest = new Session.NewPermissionsRequest(this.GetContext(), PERMISSIONS);
Session.getActiveSession().requestNewReadPermissions(reauthRequest);
return;
}
}
this.runOnUiThread(new Runnable()
{
#Override
public void run()
{
Request request = new Request(Session.getActiveSession(), "me/feed", _postParameter, HttpMethod.POST);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
});
}
But it posts my app page details instead of the *_postParameter* i give.
I also tried to use 2 other methods but it didn't post anything
Map<String, Object> params = new HashMap<String, Object>();
params.put("name", name);
params.put("link", link);
params.put("picture", link_to_image);
params.put("caption", caption);
params.put("description", description);
JSONObject jfeed = new JSONObject(params);
final GraphObject _feed = GraphObject.Factory.create(jfeed);
Request.executePostRequestAsync(Session.getActiveSession(), "https://graph.facebook.com/"+userID+"/feed", _feed, new Request.Callback()
{
#Override
public void onCompleted(Response response)
{
Log.i("tag", response.toString());
}
});
Second method is
Request.executeRestRequestAsync(Session.getActiveSession(), "stream.publish", _postParameter, HttpMethod.POST);
I found out what the problem was. I was not asking the right permissions and the graph path was also wrong. The right method is :
public static void PublishToFeedInBackground()
{
final Bundle _postParameter = new Bundle();
_postParameter.putString("name", name);
_postParameter.putString("link", link);
_postParameter.putString("picture", link_to_image);
_postParameter.putString("caption", caption);
_postParameter.putString("description", description);
final List<String> PERMISSIONS = Arrays.asList("publish_stream");
if (Session.getActiveSession() != null)
{
NewPermissionsRequest reauthRequest = new Session.NewPermissionsRequest(this.GetContext(), PERMISSIONS);
Session.getActiveSession().requestNewPublishPermissions(reauthRequest);
}
this.runOnUiThread(new Runnable()
{
#Override
public void run()
{
Request request = new Request(Session.getActiveSession(), "feed", _postParameter, HttpMethod.POST);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
});
}
As far as I know, this was possible with the REST api which is now deprecated... https://developers.facebook.com/docs/reference/rest/
EDIT: here are the functions you can use to post https://developers.facebook.com/docs/reference/rest/#publishing-methods
I would get user likes from facebook using Android sdk 3.0 beta.
How do I do this?
Provided that you have a valid session, this is the code to get the user likes
Session session = Session.getActiveSession();
Request.Callback callback = new Request.Callback() {
#Override
public void onCompleted(Response response) {
// response should have the likes
Toast.makeText(getApplicationContext(), response.toString(), Toast.LENGTH_LONG).show();
}
};
Request request = new Request(session, "me/likes", null, HttpMethod.GET, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();