当我使用HelloFacebookSample时,代码工作正常,我可以在用户墙上发布。
但是当我尝试发布视频并将其嵌入到墙上 时,我使用发布来提供教程
当我转换我的代码时,我 postStatusUpdate()
用publishStory()
public void postStatusUpdate() {
if (user != null && hasPublishPermission()) {
final String message ;
message = ( user.getFirstName()+" "+ getString( R.string.status_update_link)+ " " +video_id + " " + getString(R.string.google_play_link));
Request request = Request
.newStatusUpdateRequest(Session.getActiveSession(), message, new Request.Callback() {
@Override
public void onCompleted(Response response) {
showPublishResult(message, response.getGraphObject(), response.getError());
}
});
request.executeAsync();
} else {
pendingAction = PendingAction.POST_STATUS_UPDATE;
}
}
替换为:
private void publishStory() {
Session session = Session.getActiveSession();
if (session != null){
// Check for publish permissions
List<String> permissions = session.getPermissions();
if (!isSubsetOf(PERMISSIONS, permissions)) {
Session.NewPermissionsRequest newPermissionsRequest = new Session
.NewPermissionsRequest(this, PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
return;
}
Bundle postParams = new Bundle();
postParams.putString("message", getString( R.string.google_play_link));
postParams.putString("link", "http://www.youtube.com/watch?v="+ video_id);
postParams.putString("source", "http://www.youtube.com/v/" + video_id);
postParams.putString("picture","http://img.youtube.com/vi/" +video_id + "/0.jpg");
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(TAG,
"JSON error "+ e.getMessage());
}
FacebookRequestError error = response.getError();
if (error != null) {
Toast.makeText(MyApp.intense,
error.getErrorMessage(),
Toast.LENGTH_LONG).show();
} else {
/**
Toast.makeText(MyApp.intense,
// postId
"Sent"
,
Toast.LENGTH_LONG).show();
*/
}
}
};
Request request = new Request(session, "me/feed", postParams,
HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
}
因此,当我尝试发布时,该应用程序是 cresh 并且我收到“会话:尝试为具有待处理请求的会话请求新权限”
我没有找到第一次许可的时间...
在以这种形式发布的其他 Q 中,开发人员收到了与我收到的相同的错误消息,但是当会话未打开并且用户调用它时,似乎会出现此错误,我相信在这种情况下不是问题。
我从这个 FragmentActivity 附加了更多代码,因为我认为这是必要的。
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (pendingAction != PendingAction.NONE &&
(exception instanceof FacebookOperationCanceledException ||
exception instanceof FacebookAuthorizationException)) {
new AlertDialog.Builder(HelloFacebookSampleActivity.this)
.setTitle(R.string.cancelled)
.setMessage(R.string.permission_not_granted)
.setPositiveButton(R.string.ok, null)
.show();
postStatusUpdateButton.setEnabled(false);
pendingAction = PendingAction.NONE;
} else if (state == SessionState.OPENED_TOKEN_UPDATED) {
handlePendingAction();
}
updateUI();
}
private enum PendingAction {
NONE,
POST_STATUS_UPDATE
}
private UiLifecycleHelper uiHelper;
private Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};