其他分享
首页 > 其他分享> > 获取请求已发送到Facebook Android的用户

获取请求已发送到Facebook Android的用户

作者:互联网

我正在尝试创建一个应用程序,您可以通过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();
    }

如果有人可以帮助我,我将非常感谢!
谢谢

解决方法:

抱歉缩进

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

标签:facebook,notifications,facebook-requests,android
来源: https://codeday.me/bug/20191123/2066291.html