2013-10-08 14 views
0

我的应用程序有一个按钮,启动Facebook网页对话框。登录后,应用程序有一个对话框供用户编写一些内容,当他点击“分享”按钮时,我们代表他发布链接。帖子在用户提供错误的内容后组类似帖子

在短时间内做了2次或3次“分享”操作,Facebook将用户Feed中类似的内容进行分组,而不是显示正常内容,它显示了附件上显示的内容。用户时间轴是正常的。

我们使用以下implemetation来发布链接:

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(); 

My feed, after share same content in a short time.

我们只是做到这一点,我们可以重现,看到它的发生。

希望它有助于理解。

+0

如果您只点击一次,那么一切工作正常.. –

+0

是的,只有一次正常工作。但是,如果出现不止一个相同的内容,在我的信息源或朋友的信息中,就会出现这种情况。 –

+0

我认为它是一个线程同步的问题。 –

回答

0

我不完全知道,但我认为它是一个同步问题。当您发布代表用户的链接时,或者您可以做的是,您可以维护一个标志,以在发送新请求之前检查您的先前请求是否已完成,这更好地尝试使用同步的代码。方法1:使用synchronized关键字。

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; 
       } 
      } 
     } 

我不知道,但希望它可以帮助你。

+0

我没有在我的个人笔记本电脑中发生日蚀,所以我写的代码仅仅是一个例子。我不确定,但我已经多次搞砸了类似的问题,其中我们发布事件给服务器,并在第一次请求完成之前,如果我们再次发布相同的异常,我认为原因是你在同时。 –

+0

谢谢你的回答:),但你认为这可能是这样的?因为我认为这是奇怪的帖子得到这种方式。我也注意到,如果我的一些朋友在分享内容时分享了类似的内容,那也是一样。我想知道是否可以用API或其他东西。 –

+0

展望你的榜样,我明白我会延迟再次发布,但我相信Facebook的Feed将继续对内容进行分组,因为它们是相似的。你怎么看? –