1

所以我设法 1. 让登录工作。2. 为登录用户创建一个事件。3. 显示用户好友列表,让用户选择好友并获取好友ID。

我想用选定用户的 id 作为附加主机来更新 fb 事件。尽管尝试了几天,我还是被困住了。

请帮忙。

登录代码:

btn_login = (Button) findViewById(R.id.button1);
    btn_login.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // start Facebook Login
            Session.openActiveSession(MainActivity.this, true,
                    new Session.StatusCallback() {

                        // callback when session changes state
                        @Override
                        public void call(Session session,
                                SessionState state, Exception exception) {
                            if (session.isOpened()) {

                                // make request to the /me API
                                Request.executeMeRequestAsync(session,
                                        new Request.GraphUserCallback() {

                                            // callback after Graph API
                                            // response with user
                                            // object
                                            @Override
                                            public void onCompleted(
                                                    GraphUser user,
                                                    Response response) {
                                                if (user != null) {
                                                    TextView welcome = (TextView) findViewById(R.id.tv1);
                                                    MangoTestApplication app = (MangoTestApplication) getApplication();
                                                    app.setUser(user);
                                                    // System.out
                                                    // .println(user);
                                                    welcome.setText("Hello "
                                                            + user.getName()
                                                            + "!");
                                                }
                                            }
                                        });

                            }
                        }
                    });

事件创建:

Bundle params = new Bundle();
            // params.putString("type", "event");

            // params.putString("title", "Sample events.event");
            // params.putString("description", "");
            params.putString("name", "Test Event4");

            params.putString("start_time", "2013-07-14");

            Session.getActiveSession().requestNewPublishPermissions(
                    new Session.NewPermissionsRequest(MainActivity.this,
                            Arrays.asList(permissions)));


            Request request = new Request(Session.getActiveSession(),
                    "me/events", params, HttpMethod.POST, new Callback() {

                        @Override
                        public void onCompleted(Response response) {
                            // System.out.println(response);
                            System.out.println(response);
                            event_id = response.getGraphObject()
                                    .getProperty("id").toString();
                            try {
                                if (response.getConnection()
                                        .getResponseCode() == 200)
                                    Toast.makeText(MainActivity.this,
                                            "Event Created",
                                            Toast.LENGTH_SHORT).show();
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }

                        }
                    });
            RequestAsyncTask task = new RequestAsyncTask(request);
            task.execute();

以及添加主机的事件更新(不起作用):

Bundle params = new Bundle();
            params.putString("name", "Test Event5");
            params.putString("host", fb friends id here));

            params.putString("start_time", "2013-07-15");

            Request request = new Request(Session.getActiveSession(),
                    event_id, params, HttpMethod.POST, new Callback() {

                        @Override
                        public void onCompleted(Response response) {
                            // System.out.println(response);
                            System.out.println(response);
                            try {
                                if (response.getConnection()
                                        .getResponseCode() == 200)
                                    Toast.makeText(MainActivity.this,
                                            "Event Created",
                                            Toast.LENGTH_SHORT).show();
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }

                        }
                    });
            RequestAsyncTask task = new RequestAsyncTask(request);
            task.execute();

请注意,事件更新适用于名称/日期更改。但我无法添加更多主机。请帮忙!!!注意:代替“主机”,我还尝试将选定的朋友 ID 作为“创建者”插入包中,但它不起作用。

4

0 回答 0