How to send app requests to friends through Facebook Android SDK

android, facebook, facebook-graph-api

Solution

The android sdk has Dialogs which you can use, and when you open a dialog you specify which dialog you want to open.

You can see the list of available dialogs in the Dialogs documentation. One of the dialogs is the Requests Dialog and you can open that from the android sdk as well, something like:

Facebook facebook = new Facebook("YOUR_APP_ID");

....

Bundle params = new Bundle();
params.putString("title", "invite friends");
facebook.dialog(this, "apprequests", params, new DialogListener() {
    @Override
    public void onComplete(Bundle values) {}

    @Override
    public void onFacebookError(FacebookError error) {}

    @Override
    public void onError(DialogError e) {}

    @Override
    public void onCancel() {}
});

You can add more parameters for this dialog, use the documentation to see what it is you need.

Edit

Ok, check out this code:

Bundle paramsOut = new Bundle(), paramsIn = this.getIntent().getExtras();
paramsOut.putString("message", paramsIn.getString("message"));
this.facebook.dialog(this, "apprequests", paramsOut, new InviteListener(this));

I use it and it works well for me, the app request is being sent and the user receives it. Since your code is pretty similar, it is safe to assume that the problem is with what's different, and so you should post the code to what is different.

So, what's in that AppRequestsListener of yours? Saying that it just shows a popup does not help me to help you. Also, what is this *Hackbook"? is it an activity?

Problem

Currently I'm developing an Android app for that I'm using the Facebook SDK. It's working fine for posting messages to the wall etc., but through this SDK I'm unable to send an app request to others. Can anyone help me out? here is my code snippet: ``` Bundle params = new Bundle(); params.putString("message", getString(R.string.request_message)); Utility.mFacebook.dialog(Hackbook.this, "apprequests", params, new AppRequestsListener()); ``` and AppRequestsListener: ``` public class AppRequestsListener extends BaseDialogListener { @Override public void onComplete(Bundle values) { Toast toast = Toast.makeText(getApplicationContext(), "App request sent", Toast.LENGTH_SHORT); toast.show(); } @Override public void onFacebookError(FacebookError error) { Toast.makeText(getApplicationContext(), "Facebook Error: " + error.getMessage(), Toast.LENGTH_SHORT).show(); } @Override public void onCancel() { Toast toast = Toast.makeText(getApplicationContext(), "App request cancelled", Toast.LENGTH_SHORT); toast.show(); } } ```

Original source