3

我正在尝试创建一个应用程序,您可以通过 Facebook 请求对话框“邀请”或告诉您的朋友。https://developers.facebook.com/docs/howtos/androidsdk/3.0/send-requests/

它有点工作,但我需要做的一件事是知道请求被发送到谁。我怎样才能做到这一点?

我还有一个次要问题,请求通知仅显示在用户应用程序上 - 而不是桌面页面上。有人知道吗?

请求代码:

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();
    }

如果有人可以帮助我,我将不胜感激!谢谢

4

1 回答 1

3

抱歉缩进

 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();
于 2013-07-11T17:48:12.200 回答