3

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.

Community
  • 1
  • 1
ask
  • 2,160
  • 7
  • 31
  • 42

2 Answers2

4

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.

Nitzan Tomer
  • 155,636
  • 47
  • 315
  • 299
  • The `"id"` is the name of the parameter, and the `USER_ID` is the actual value you have at runtime which you should put there. – Nitzan Tomer Jun 24 '12 at 08:01
1

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

Hesam
  • 52,260
  • 74
  • 224
  • 365
martar
  • 448
  • 3
  • 9