0

我的应用程序有一个启动 Facebook 网络对话框的按钮。登录后,应用程序有一个对话框让用户写一些内容,当他点击“分享”按钮时,我们代表他发布一个链接。

执行 2 或 3 次“分享”动作,Facebook 在短时间内将类似的内容分组到用户供稿上,而不是显示正常内容,而是显示类似于附图中显示的内容。用户时间线正常。

我们正在使用以下实现来发布链接:

Bundle postParams = new Bundle();
postParams.putString("name", getString(R.string.app_name));
postParams.putString("caption", getResources().getString(R.string.home));
postParams.putString("description", someDescription);
postParams.putString("message", someMessage);
postParams.putString("picture", a link to a picture);
postParams.putString("link", a link to open the page to download the app);


final Request request = new Request(this.session,
"me/feed", postParams, HttpMethod.POST);

request.setCallback(new Request.Callback() {
@Override
public void onCompleted(final Response response) {
final FacebookRequestError error = response.getError();

  if (error == null) {
   // Do something
  } else {
   switch (error.getErrorCode()) {
    case FEED_LIMIT:
     // Do something
    break;

    case DUPLICATE_MESSAGE:
     // Do something
    break;

    case MISSING_MESSAGE:
    // Do something
    break;

    case CONNECTION:
     // Do something
     break;

    default:
    // Do something
    break;
  }
}});


request.executeAsync();

我的提要,在短时间内分享了相同的内容。

我们只是这样做,我们可以重现并看到它发生。

希望对理解有所帮助。

4

1 回答 1

0

我不确切知道,但我认为这是一个同步问题。当您代表用户发布链接时,最好使用同步来尝试您的代码,或者您可以做的是维护一个标志以在发送新请求之前检查您的先前请求是否已完成。

方法一:使用同步关键字。

void post_request () {
    synchronized (request) {
        //post your link here and wait for your request completion.
    }
}

方法2:维护一个标志。

boolean is_request_in_process = false;

void post_request () {
      if (!is_request_in_process) {
           is_request_in_process = true;
           // post your request here and wait for confirmation.
           // after completion is_request_in_process = false;
      }
}

您还可以结合方法和检查:

Request request_obj = null;
boolean is_request_in_process = false;

    void post_request () {
        synchronized (request_obj) {
              if (!is_request_in_process) {
                   is_request_in_process = true;
                   // post your request here and wait for confirmation.
                   // after completion is_request_in_process = false;
              }
           }
        }

我不确定,但希望它可以帮助你。

于 2013-10-08T17:01:59.460 回答