3

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.

Bala
  • 115
  • 1
  • 2
  • 5

2 Answers2

8

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();
}
Oren Bengigi
  • 994
  • 9
  • 17
  • Hi,In old i will add like this params.putString("to", userIDString); params.putString("message", Message);. now where i will give the Friends user Id?? – Jeeva123 Feb 18 '13 at 10:08
  • 1
    @Ramachandran use setTo(String id) method. https://developers.facebook.com/docs/reference/android/3.0/WebDialog.RequestsDialogBuilder – ChangUZ Jun 03 '13 at 02:43
4

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.

rightparen
  • 1,693
  • 10
  • 15
  • Thanks! Didn't realize doing it the old way was not deprecated. – Bala Oct 21 '12 at 01:07
  • This method is deprecated, in fact instantiating the "Facebook" class is deprecated. Please provide another solution. – Elad Nava Dec 24 '12 at 17:40
  • Updated instructions to reflect the new API in the final bits. – rightparen Dec 26 '12 at 21:42
  • Hi,In old i will add like this params.putString("to", userIDString); params.putString("message", Message);. now where i will give the Friends user Id?? – Jeeva123 Feb 18 '13 at 10:07
  • To add parameters, after you create a new WebDialog.Builder(), call builder.getParameters(), add any parameters you want to the returned Bundle, and then call builder.build() to create the WebDialog. – rightparen Feb 18 '13 at 19:41