3

I'm trying to create a application were you can "invite" or tell your friends about it through the Facebook request dialog. https://developers.facebook.com/docs/howtos/androidsdk/3.0/send-requests/

It works somewhat but one thing I need is to know who the requests were sent TO. How can I do this?

I also have a secondary issue where the request notification only shows up on the users app - not on the desktop page. Anyone know anything about that?

Request code:

private void sendRequestDialog() {
        Bundle params = new Bundle();
        params.putString("message", "!");

        WebDialog requestsDialog = (
            new WebDialog.RequestsDialogBuilder(MyPage.this, Session.getActiveSession(), params))
                .setOnCompleteListener(new OnCompleteListener() {

                    @Override
                    public void onComplete(Bundle values, FacebookException error) {
                        if (error != null) {
                            if (error instanceof FacebookOperationCanceledException) {
                                Toast.makeText(MyPage.this, 
                                    "Inbjudan avbruten", 
                                    Toast.LENGTH_SHORT).show();
                            } else {
                                Toast.makeText(MyPage.this, "Nätverksfel, kontrollera din anslutning och försök igen", Toast.LENGTH_SHORT).show();
                            }
                        } else {
                            final String requestId = values.getString("request");
                            if (requestId != null) {
                                Toast.makeText(MyPage.this, "Inbjudan skickad", Toast.LENGTH_SHORT).show();
                            } else {
                                Toast.makeText(MyPage.this, "Inbjudan avbruten", Toast.LENGTH_SHORT).show();
                            }
                        }   
                    }



                })
                .build();
        requestsDialog.show();
    }

If anyone can help me with this I'm very grateful! Thank you

PaperThick
  • 2,749
  • 4
  • 24
  • 42

1 Answers1

3

Sorry about indentation

 Bundle params = new Bundle();
 RequestsDialogBuilder builder = new WebDialog.RequestsDialogBuilder(activity, Session.getActiveSession(), params);
 builder.setOnCompleteListener(new OnCompleteListener() {

@Override
public void onComplete(Bundle values, FacebookException error) {
if (error == null) {
    if (values.containsKey("request")) {

        Set<String> keys = values.keySet();

        for(String key:keys) {
            if(key.contains("to[")) {
                //I know this keys are horrible, but that's how facebook did it
                //Here you have the id's to do something with it
                Logger.d("FACEBOOK", "key " + key + " vlaue " + values.getString(key));                     
            }

        }
    } else {
        if (listener instanceof IFacebookCancelableListener) {
            ((IFacebookCancelableListener) listener).onCancel();
        }
    }
} else if (error instanceof FacebookOperationCanceledException) {
    if (listener instanceof IFacebookCancelableListener) {
        ((IFacebookCancelableListener) listener).onCancel();
    }
} else {
   //Error
}
}
});
WebDialog dialog = builder.build();
dialog.show();
Moxor
  • 1,868
  • 17
  • 13
  • 2
    Thank you for the tip. I spent one hour to try to get the key "to" from Bundle values and always get null. Until I see your answer. Wow, I can't believe it has such ugly "to" key name :|. Again, thank you so much @Moxor :) – Blue Smith Sep 30 '13 at 03:46