我正在尝试使用以下代码发布facebook:
Session session = Session.getActiveSession();
if (session != null) {
Bundle postParams = new Bundle();
postParams.putString("name", "Facebook SDK for Android");
Request.Callback callback = new Request.Callback() {
public void onCompleted(Response response) {
JSONObject graphResponse = response
.getGraphObject()
.getInnerJSONObject();
String postId = null;
try {
postId = graphResponse.getString("id");
} catch (JSONException e) {
Log.i("error",
"JSON error " + e.getMessage());
}
}
};
Request request = new Request(session, "me/feed", postParams,
HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
} else {
Session.setActiveSession(new Session(this));
Session.getActiveSession().getActiveSeopenForPublish(new Session.OpenRequest(this)
.setPermissions(Arrays.asList("publish_stream"))
.setCallback(new SessionStatusCallback()));
}
它无效,我在响应response.getGraphObject上获得空指针异常。 请帮忙