所以我成功了 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插入"创建者"而不是" host"在捆绑中,但它有效。