【发布时间】:2014-07-04 11:41:56
【问题描述】:
我正在开发一个小型 android 项目来创建 facebook 事件并在其上分享照片。好吧,我在登录和注销方法方面取得了成功,但我仍然阻止创建新事件,我尝试使用旧方法:
Bundle params = new Bundle();
params.putString("privacy_type", "OPEN");
params.putString("name", "This is a test event");
params.putString("start_time", "2013-12-02T18:00:00+0530");
params.putString("end_time", "2013-12-02T20:00:00+0530");
params.putString("description", "This is test description yeah?.");
params.putString("location", "Mount Lavinia");
params.putString("privacy_type", "OPEN");
String response = "";
Facebook facebook = new Facebook(APP_ID);
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request("me/events", params, "POST",
new RequestListener() {
public void onComplete(String response, Object state) {
try {
Log.i(TAG, "start");
JSONObject event = new JSONObject(response);
Log.i(TAG, response);
String event_id = event.getString("id");
Log.i(TAG, "end");
Log.i(TAG, "Event id => " + event_id);
// Toast.makeText(getApplicationContext(),
// "New Event Created!!",
// Toast.LENGTH_LONG).show();
} catch (Exception e) {
}
}
}, null);
还有新方法:
Session session = Session.getActiveSession();
Bundle params = new Bundle();
params.putString("privacy_type", "OPEN");
params.putString("name", "This is a test event");
params.putString("start_time", "2013-12-02T18:00:00+0530");
params.putString("end_time", "2013-12-02T20:00:00+0530");
params.putString("description", "This is test description yeah?.");
params.putString("location", "Mount Lavinia");
new Request(
session,
"me/events",
params,
HttpMethod.POST,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
try {
Log.i(TAG, response.toString());
// Toast.makeText(getApplicationContext(),
// "New Event Created!!",
// Toast.LENGTH_LONG).show();
} catch (Exception e) {
Log.i(TAG, "noresponse");
}
}
}
).executeAsync();
但我总是在 LogCat 中得到这个:
07-04 05:50:48.749: I/MainActivity(3159): {Response: responseCode: 200, graphObject: null, error: {HttpStatus: -1, errorCode: -1, errorType: null, errorMessage: java .lang.NullPointerException}, isFromCache:false}
【问题讨论】: