好的,所以我想在我的用户墙上发布一个新帖子。我已经按照developers.facebook在此链接上提供的代码https://developers.facebook.com/docs/howtos/androidsdk/3.0/publish-to-feed/
在发布故事方法中,我添加了一个日志以查看程序是否通过了代码行:
private void publishStory() {
Session session = Session.getActiveSession();
if (session != null){
Log.d("INFO","session is not NULL");
// Check for publish permissions
List<String> permissions = session.getPermissions();
if (!isSubsetOf(PERMISSIONS, permissions)) {
Log.d("INFO","setting permission");
pendingPublishReauthorization = true;
Session.NewPermissionsRequest newPermissionsRequest = new Session
.NewPermissionsRequest(this, PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
return;
}
Bundle postParams = new Bundle();
postParams.putString("name", "Facebook SDK for Android");
postParams.putString("caption", "Build great social apps and get more installs.");
postParams.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
postParams.putString("link", "https://developers.facebook.com/android");
postParams.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
Log.d("INFO","finish construct message");
Request.Callback callback= new Request.Callback() {
public void onCompleted(Response response) {
Log.d("INFO","on request complete!");
JSONObject graphResponse = response
.getGraphObject()
.getInnerJSONObject();
String postId = null;
try {
postId = graphResponse.getString("id");
} catch (JSONException e) {
Log.i(TAG,
"JSON error "+ e.getMessage());
}
FacebookRequestError error = response.getError();
if (error != null) {
Toast.makeText(getActivity()
.getApplicationContext(),
error.getErrorMessage(),
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity()
.getApplicationContext(),
postId,
Toast.LENGTH_LONG).show();
}
}
};
Request request = new Request(session, "me/feed", postParams,
HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
}
问题是当我执行上面的方法时,程序运行良好,直到它弹出一个身份验证发布权限窗口并且我允许它,屏幕再次继续黑屏,上面有不确定的进度条,然后窗口自行关闭.
事实上,从 logcat 我可以得出结论,它没有通过“on request complete”行。
为什么会这样?任何线索?
谢谢!