Bundle params = new Bundle();
params.putString("to", useriId);
params.putString("message","Hello World");
WebDialog requestsDialog = (new WebDialog.RequestsDialogBuilder(
JoinVia.this, Session.getActiveSession(), params))
.setOnCompleteListener(new OnCompleteListener() {
#Override
public void onComplete(Bundle values,
FacebookException error) {
if (error != null) {
if (error instanceof FacebookOperationCanceledException) {
Toast.makeText(
JoinVia.this.getApplicationContext(),
"Request cancelled", Toast.LENGTH_SHORT)
.show();
} else {
Toast.makeText(
JoinVia.this.getApplicationContext(),
"Network Error", Toast.LENGTH_SHORT)
.show();
}
} else {
final String requestId = values
.getString("request");
if (requestId != null) {
Toast.makeText(
JoinVia.this.getApplicationContext(),
"Request sent", Toast.LENGTH_SHORT)
.show();
} else {
Toast.makeText(
JoinVia.this.getApplicationContext(),
"Request cancelled", Toast.LENGTH_SHORT)
.show();
}
}
}
}).build();
requestsDialog.show();
This my code to send invitation to friends id. The code can send the notification, but when i click the notification icon from the browser, the invitation is not present. Can anyone guide me how to send a message to friends facebook.
UPDATED:
Ignore my previous answer, I misinterpreted the type of dialog that you were trying to produce.
As mentioned in the comments, your code doesn't seem to be the problem since you are successfully getting a notification. Simply follow the steps in the Facebook app creation doc to make sure you are setting your app up correctly, specifying a Canvas URL as shown in the first image to make sure your app can provide invitations properly.
The examples on the same page should provide more help with using the URLs also.
Related
As per this link here, I have installed the SDK 3.2.1 and implemented a uiHelper, along with FacebookDialog like this:
if (FacebookDialog.canPresentShareDialog(getApplicationContext(),
FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) {
// Publish the post using the Share Dialog
Toast.makeText(this, "if", Toast.LENGTH_LONG).show();
FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(
this).setLink("https://developers.facebook.com/android")
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
} else {
Toast.makeText(this, "else", Toast.LENGTH_LONG).show();
// Fallback. For example, publish the post using the Feed Dialog
publishFeedDialog();
}
For publishFeedDialog() I have:
private void publishFeedDialog() {
Bundle params = new Bundle();
params.putString("name", "Facebook SDK for Android");
params.putString("caption",
"Build great social apps and get more installs.");
params.putString(
"description",
"The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
params.putString("link", "https://developers.facebook.com/android");
params.putString("picture",
"https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(this,
Session.getActiveSession(), params)).setOnCompleteListener(
new OnCompleteListener() {
#Override
public void onComplete(Bundle values,
FacebookException error) {
if (error == null) {
// When the story is posted, echo the success
// and the post Id.
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(getApplicationContext(),
"Posted story, id: " + postId,
Toast.LENGTH_SHORT).show();
} else {
// User clicked the Cancel button
Toast.makeText(getApplicationContext(),
"Publish cancelled", Toast.LENGTH_SHORT)
.show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(getApplicationContext(),
"Publish cancelled", Toast.LENGTH_SHORT)
.show();
} else {
// Generic, ex: network error
Toast.makeText(getApplicationContext(),
"Error posting story", Toast.LENGTH_SHORT)
.show();
}
}
}).build();
feedDialog.show();
}
Now the FacebookDialog.canPresentShareDialog is always going to false even when Fb app is installed in the phone and then the publishFeedDialog() is called. But the app crashes after this.
What is the solution for this? Why is the normal facebook dialog shown when the app is there in my phone? (I am using Lenevo model, if that helps)
You need a newer FB app in order for the share dialog to work. Make sure you download the latest ones!
Also, no, you don't need login to enable the share dialog.
Im trying to use facebook request dialog to enable the user to pick a friend to challenge in a turn based trivia android game.
i dont have a web version of the game so i dont canvas.
ive set up a request dialog that shows the list friends which works fine when i log in with facebook test users but when i login with my user who is also administrator of the facebook app then the dialog shows a list of only 5 friends. the dialog allows to search for more friends and when i do that i can search for other friends which do not appear in the list.
my user has "public_profile","read_friendlists", "user_friends" permissions.
the request dialog code
private void sendRequestDialog() {
Bundle params = new Bundle();
params.putString("message", "Learn how to make your Android apps social");
params.putString("filters", "app_non_users");
WebDialog requestsDialog = (
new WebDialog.RequestsDialogBuilder(MainActivity.this,
//getActivity(),
Session.getActiveSession(),
params))
.setOnCompleteListener(new OnCompleteListener() {
#Override
public void onComplete(Bundle values,
FacebookException error) {
if (error != null) {
if (error instanceof FacebookOperationCanceledException) {
Toast.makeText(getApplicationContext(),
//getActivity().getApplicationContext(),
"Request cancelled",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(),
//getActivity().getApplicationContext(),
"Network Error",
Toast.LENGTH_SHORT).show();
}
} else {
final String requestId = values.getString("request");
if (requestId != null) {
Toast.makeText(getApplicationContext(),
//getActivity().getApplicationContext(),
"Request sent",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(),
//getActivity().getApplicationContext(),
"Request cancelled",
Toast.LENGTH_SHORT).show();
}
}
}
})
.build();
requestsDialog.show();
}
i dont understand why its not showing the entire friends list. please help.
in addition, is this method of challenging a friend for a game is permitted by facebook is there another more recommended method?
Thanks!
user_friends will return only the friends who used the app that makes the request. via Graph API Reference
I think, this is very simple problem. I have one button in my app. If i click it it executes one method. In this method i want to share "Hi this is xxx using xxxxx product" message on user's facebook wall. How can i do that? Is there any tutorials?
myMethod(){
//share on fb wall
}
From Sharing in Android tutorial:
Prerequisites
Before you can share to Facebook from your app, or attempt to follow
any of the sharing tutorials, you will need:
Your environment set up A Facebook app properly configured and linked
to your Android app, with SSO enabled The Facebook SDK added to your
project If you haven't done this and need help doing so, you can
follow our getting started guide.
Then essentially, have your myMethod call this:
private void publishFeedDialog() {
Bundle params = new Bundle();
params.putString("name", "Facebook SDK for Android");
params.putString("caption", "Build great social apps and get more installs.");
params.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
params.putString("link", "https://developers.facebook.com/android");
params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
WebDialog feedDialog = (
new WebDialog.FeedDialogBuilder(getActivity(),
Session.getActiveSession(),
params))
.setOnCompleteListener(new OnCompleteListener() {
#Override
public void onComplete(Bundle values,
FacebookException error) {
if (error == null) {
// When the story is posted, echo the success
// and the post Id.
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(getActivity(),
"Posted story, id: "+postId,
Toast.LENGTH_SHORT).show();
} else {
// User clicked the Cancel button
Toast.makeText(getActivity().getApplicationContext(),
"Publish cancelled",
Toast.LENGTH_SHORT).show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(getActivity().getApplicationContext(),
"Publish cancelled",
Toast.LENGTH_SHORT).show();
} else {
// Generic, ex: network error
Toast.makeText(getActivity().getApplicationContext(),
"Error posting story",
Toast.LENGTH_SHORT).show();
}
}
})
.build();
feedDialog.show();
}
Hi I have problem with Facebook:
Case:
1.User has no Facebook app.
2.User logins into Facebook via WebDialog
3.User gives all permissions for share, and shares post
4.User enters Facebook account, than into applications, and removes my app.
5.User tries to make share again.
6."Unknown error. Please try again later" Appears in WebDialog.
Is there a way to fix this case?
I found that using ShareDialog i can avoid this problem when user has facebook app installed, but I don't know how to solve it if user has no fb app on his phone.
To show dialog I verify:
private boolean checkFacebookLogin(){
Session session = Session.getActiveSession();
if(session!=null && session.isOpened() ){
return true;
}
return false;
}
Than i ask for permissions if they are needed:
private void performPublish() {
Session session = Session.getActiveSession();
pendingAction = PendingAction.POST_STATUS_UPDATE;
if (session != null && mCurrentActivity!=null) {
if (hasPublishPermission()) {
// We can do the action right away.
handlePendingAction();
} else {
// We need to get new permissions, then complete the action when we get called back.
session.requestNewPublishPermissions(new Session.NewPermissionsRequest(mCurrentActivity, PERMISSIONS));
}
}
}
In the end i show WebDialog:
WebDialog feedDialog = (
new WebDialog.FeedDialogBuilder(mCurrentActivity,
Session.getActiveSession(),
postParams))
.setOnCompleteListener(new OnCompleteListener() {
#Override
public void onComplete(Bundle values,
FacebookException error) {
}
})
.build();
feedDialog.show();
After showing WebDialog, it redirects to error page with "Unknow error [...]" text, i have found no error information, so I don't even know that something goes wrong.
I tried HelloFacebookSample, but there if user has no facebook app, he can't edit post in facebook dialog. I want to see Facebook dialog in both cases ( with/without fb app installed).
if (FacebookDialog.canPresentShareDialog(this,
FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) {
FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(
this)
.setLink(// what ever you want to share use here
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
} else {
Session session = Session.getActiveSession();
if (session != null && session.isOpened()) {
Log.d("Tag", "Success!");
publishFeedDialog();
} else {
//ask the user to login .
//authButton.performClick();
share = true;
// }
}
So from the above code if the fb app is already installed it will open that app else you have to ask the user to login by performing Fb LoginButton . performClick(). so the user will be redirected to web dialog of fb login. the onLogin success call back u can share using.,
private void publishFeedDialog() {
Bundle params = new Bundle();
params.putString("link",
"");
WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(
MenuActivity.this, Session.getActiveSession(), params))
.setOnCompleteListener(new OnCompleteListener() {
#Override
public void onComplete(Bundle values,
FacebookException error) {
if (error == null) {
// When the story is posted, echo the success
// and the post Id.
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(MenuActivity.this, "Posted",
Toast.LENGTH_SHORT).show();
} else {
// User clicked the Cancel button
Toast.makeText(
MenuActivity.this
.getApplicationContext(),
"Publish cancelled", Toast.LENGTH_SHORT)
.show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(
MenuActivity.this.getApplicationContext(),
"Publish cancelled", Toast.LENGTH_SHORT)
.show();
} else {
// Generic, ex: network error
Toast.makeText(
MenuActivity.this.getApplicationContext(),
"Error posting story", Toast.LENGTH_SHORT)
.show();
}
}
}).build();
feedDialog.show();
}
I am trying to tag one friend in my wall post. But this 'tags' parameter isn't working. How can i tag one/more friends? Pls help me. Thank you in advance.
Bundle params = new Bundle();
params.putString("tags", tagged_friends_id);
WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(this, Session.getActiveSession(),params))
.setOnCompleteListener(new OnCompleteListener() {
#Override
public void onComplete(Bundle values, FacebookException error) {
if (error == null) {
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(MainActivity.this,"Posted story, id: "+postId, Toast.LENGTH_SHORT).show();
}
else {
// User clicked the Cancel button
Toast.makeText(MainActivity.this, "Publish cancelled", Toast.LENGTH_SHORT).show();
}
}
else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(MainActivity.this, "Publish cancelled", Toast.LENGTH_SHORT).show();
}
else {
// Generic, ex: network error
Toast.makeText(MainActivity.this, "Error posting story", Toast.LENGTH_SHORT).show();
}
}
}).build();
feedDialog.show();
You can tag multiple friends using the "tags" key itself.
But the syntax needs to be bit different. The friend ids must be appended in a string separated by comma. There should not be any spaces between the ids.
For eg:
params.putString("tags", "xxxxx1,xxxxx2");
This worked perfectly for me.
As Ming have mentioned, you can not tag friends using the Feed Dialog.
The only way to tag friends in a post, is using the Open Graph Concept- Mention Tagging
See the documentation for the supported parameters to the Feed dialog here:
https://developers.facebook.com/docs/reference/dialogs/feed/
The Feed dialog does not support "tags".