Invite Friend Request using new Android SDK 3.0 - android

I am using the new Facebook SDK 3.0 that just released on Android. I want to let the user invite his/her friends to the app.
However, in the new SDK you do NOT create a new Facebook object with the App ID. You extend the FacebookActivity as given in the tutorial: http://developers.facebook.com/docs/tutorials/androidsdk/3.0/scrumptious/authenticate/
Hence, I could not use the reference material provided to send invites to friends since there is no facebook object to call the dialog method on.
http://developers.facebook.com/docs/howtos/androidsdk/3.0/send-requests/
I've already setup the Friend Picker UI and can get GraphUser objects that the user selected.
http:// developers(dot)facebook(dot)com/docs/tutorials/androidsdk/3.0/scrumptious/show-friends/
But, I can't figure out how to invite the friends that the user has selected.
Does anyone know how to invite friends in the new SDK? Would you be using the FbDialog class? If so, what is the url string that needs to be provided? (I tried using "apprequests", but that didn't work)
Thanks for your help.

Try this link:
https://developers.facebook.com/docs/howtos/androidsdk/3.0/send-requests/
private void sendRequestDialog() {
Bundle params = new Bundle();
params.putString("message", "Learn how to make your Android apps social");
WebDialog requestsDialog = (
new WebDialog.RequestsDialogBuilder(getActivity(),
Session.getActiveSession(),
params))
.setOnCompleteListener(new OnCompleteListener() {
#Override
public void onComplete(Bundle values,
FacebookException error) {
final String requestId = values.getString("request");
if (requestId != null) {
Toast.makeText(getActivity().getApplicationContext(),
"Request sent",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Request cancelled",
Toast.LENGTH_SHORT).show();
}
}
})
.build();
requestsDialog.show();
}

You can use com.facebook.widget.WebDialog class for this:
WebDialog dialog = new WebDialog.Builder(myActivity, mySession, ...).build();
dialog.show();
Also see helper classes WebDialog.FeedDialogBuilder and WebDialog.RequestsDialogBuilder that make it easier to build these dialogs.

Related

facebook request dialog android shows only a partial list of friends

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

Send Facebook request from android does not show message preview and does not send to friends

In my android app, after the Facebook login and authentication, user is allowed to send the request to his friend to invite them to join the app. Moreover, I need to know who is invited, after the user sends requests.
My problems are as following:
When user wants to send request, the message preview is not
showing at the top of dialog box.
When user tap on invite button, a black screen cover dialog box. if
tap on black cover, it is disappearing.
When user selects friends and tap on send, the request is not going
to the friends.
Send request code is as following:
private void sendRequestDialog() {
Bundle params = new Bundle();
params.putString("message", "Learn how to make your Android apps social");
WebDialog requestsDialog = (new WebDialog.RequestsDialogBuilder(FBLoginActivity.this, Session.getActiveSession(), params))
.setOnCompleteListener(new OnCompleteListener() {
#Override
public void onComplete(Bundle values, FacebookException error) {
if (error != null) {
if (error instanceof FacebookOperationCanceledException) {
Toast.makeText(FBLoginActivity.this, "Request cancelled", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(FBLoginActivity.this, "Network Error", Toast.LENGTH_SHORT).show();
}
} else {
final String requestId = values.getString("request");
if (requestId != null) {
Toast.makeText(FBLoginActivity.this, "Request sent", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(FBLoginActivity.this, "Request cancelled", Toast.LENGTH_SHORT).show();
}
}
}
}).build();
requestsDialog.show();
}
I followed the Facebook Send request implementation guide but I am not getting same result.
Note:
My application is not published on Play store yet.
App configuration on Facebook developer dashboard: Sand box disabled and it has not submitted to the Facebook for any permissions and approval.(I want to know for send request I need to do that?)
I am suspecting that I am missing some configuration on Facebook app dashboard.
I am appreciated for any help.
Finally I got the answer. The missing point for sending request to friend from your app is to provide Facebook configuration to handle request properly which is not mentioned in Facebook documentation.
In Facebook dashboard, go the setting and add App on Facebook (Add platform section), facebook allocate a page in Facebook domain like https://apps.facebook.com/Your-name-space, then you could set your Canvas URL and Canvas Secure URL to bring the URL content to the canvas.
(for more info about how to configure Canvas URL refer to [this][https://devcenter.heroku.com/articles/configuring-your-facebook-app-as-a-canvas-page]
After all when send request to friends, friends recieve notification and when click on it they will redirect to https://apps.facebook.com/Your-name-space.
Your code above doesn't have target/destination id.
before sending a request you need to:
Get the list of facebook friends (example here: Android: get facebook friends list)
Show a dialog with friends... (an activity.. fragment.. or anything else.) and let user choose friend he want to invite (You need target user identifier ID)
Send the request in the following way:
Bundle postParams = new Bundle();
postParams.putString("message", title);
postParams.putString("data", message);
postParams.putString("to", target);
WebDialog requestsDialog = (new WebDialog.RequestsDialogBuilder(getMainActivity(), Session.getActiveSession(), postParams)).setOnCompleteListener(new ApplicationRequestCallback()).build();
where ApplicationRequestCallback is a class that implements OnCompleteListener
Ahmadi , Even i faced the similar issue . Later i fixed by disabling from sandboxmode and Providing Canvas URL in facebook app registration. If this answer is helpful reply back.

How to do a Facebook Send Request to a specific friend on Android?

It seems that the native Request Dialog shows a list where you can choose the friends you want to invite. I'm trying to do something where the user can just press a button to invite a specific person, say a girlfriend, or a family member.
Is this possible using the native Android SDK?
Update:
Okay, this was voted to be closed so I'm updating. There wasn't anything said in the Facebook tutorials that you can send a Facebook Request to a specific person, which I was trying to do.
I've tried the following but it displays a friend selector with all of the user's friends:
Bundle params = new Bundle();
params.putString("message", "Invite message here");
WebDialog requestsDialog = (
new WebDialog.RequestsDialogBuilder(getActivity(),
Session.getActiveSession(),
params))
.setOnCompleteListener(new OnCompleteListener() {
#Override
public void onComplete(Bundle values, FacebookException error) {
// Some onComplete callback here
}
}).build();
requestsDialog.show();
And by adding .setTo(id) where id is the UID of the user to invite before .build(), the dialog is modified to send to just the indicated user. The code looks like:
WebDialog requestsDialog = (
new WebDialog.RequestsDialogBuilder(getActivity(),
Session.getActiveSession(),
params))
.setOnCompleteListener(new OnCompleteListener() {
#Override
public void onComplete(Bundle values, FacebookException error) {
// Some onComplete callback here
}
}).setTo("SOME_FACEBOOK_ID_HERE").build();
requestsDialog.show();
Actually, I just read the documentation of the Request Dialog again. And it can be configured to send to a specific person by doing .setTo(String id).
Thanks for the reply though. :)

Android Facebook FeedDialogBuilder post privacy/audience

I'm trying to allow a user to post there status to their FB wall from with in my Android app. I'm having a problem with the Privacy/Audience for the post is always set to "Only Me" I want to set this to "Friends", but I can't find a way to do this. Below is my code snippet of how i'm accomplishing this:
Bundle params = new Bundle();
params.putString("description", " ");
params.putString("name", "testtest app");
params.putString("link", "http://www.testtestapp.com/");
WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(QuickCalc.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) {
} else {
// User clicked the Cancel button
}
} else {
// Generic, ex: network error
}
}
})
.build();
feedDialog.show();
The audience level is set when the user first authorizes your app with write permissions, and cannot be changed by the app (for pretty obvious reasons).
When you ask for write permissions, you can request a certain default audience level by calling the setDefaultAudience method, but the user can edit the app settings from the Facebook website, and change the audience setting at any time.

How to send friend request using Facebook dialogs on Android?

I want tot send a friend request using the Facebook Android SDK. I'm currently using this code (which I got from here):
Bundle parameters = new Bundle();
parameters.putString("APP_ID","USERNAME");
facebook.dialog(this, "friends", parameters, this);
where APP_ID is the Facebook ID of my app and USERNAME is the username of the friend I want to add. This leads to the following error:
API Error Code:100
Invalid parameter
The parameter id is required
I thought the id parameter meant the APP_ID.
I have gone through the relevant documentation regarding dialogs at http://developers.facebook.com/docs/reference/dialogs/friends/ and http://developers.facebook.com/docs/reference/androidsdk/dialog/, but still can't figure it out.
Any help is appreciated.
Should be something like:
Bundle parameters = new Bundle();
parameters.putString("id", USER_ID);
facebook.dialog(this, "friends", parameters, this);
In case that this is an activity which also implements DialogListener.
As it says in the documentation:
app_id - Your application's identifier. Required, but automatically
specified by most SDKs.
id - Required. The ID or username of the
target user to add as a friend.
You can use:
WebDialog.RequestsDialogBuilder requestBuilder = (new WebDialog.RequestsDialogBuilder(this,
Session.getActiveSession(), params)).setOnCompleteListener(
new OnCompleteListener() {
#Override
public void onComplete(Bundle values,
FacebookException error) {
if (error != null) {
} else {
final String requestId = values
.getString("request");
if (requestId != null) {
//if the user completed the action,
} else {
}
}
}
});
WebDialog requests = requestBuilder.build();
requests.show();
If you want to set the request to preselected friends just add the following to the requestBuilder:
requestBuilder.setTo("FRIEND_ID, ANOTHER_FRIEND_ID"), before building the dialog.
What is strange is that it accepts the list of friends as a concatenated list of ids, not an Array nor list. I didn't find in in the docs, but just found that it works

Categories

Resources