简体   繁体   English

Facebook图形API,自定义操作上的FB.api发布第一次失败,但第二次成功

[英]Facebook graph API, FB.api post on custom action fails first time but succeeds second time

I have started dabbling with Facebook Graph api fairly recently. 我最近刚开始使用Facebook Graph API。 I have defined a custom action 'Start' with the namespace 'Test', here is the code I use to for posting to Facebook. 我用名称空间“ Test”定义了一个自定义动作“ Start”,这是我用来发布到Facebook的代码。

FB.api('/me/Test:start',{ article : currentURL, message: $j('.subject-content h2 a').html()}, 'post', function(response) {

                                  if (!response || response.error) {
                                       console.log('Error  '+response.error.message);
                                  }
                                  else {
                                       console.log('Message was posted! (post id: ' + response.id + ")");
                                  }
                             });

for some reason this post fails the first time, but on subsequent tries, the post succeeds. 由于某种原因,该帖子第一次失败,但是在随后的尝试中,该帖子成功了。

Here are the requests I captured from firebug. 这是我从Firebug捕获的请求。

1) 1)

        access_token    xxxxx
        article https://testserver:8080/xxx
        callback    FB._callbacks.__gcb2
        message testpage
        method  post
        pretty  0
        sdk joey   

2) 2)

    access_token    yyyy
    article https://testserver:8080/xxx
    callback    FB._callbacks.__gcb6
    message testpage
    method  post
    pretty  0
    sdk joey

As you can see the calls are exactly the same. 如您所见,调用完全相同。 The first time I get this response 我第一次得到这个回应

/**/ FB._callbacks.__gcb4({"error":{"message":"An unknown error has occurred.","type":"OAuthException","code":1}});

I tried the same requests on the graph explorer as well, it works every single time. 我也在图浏览器上尝试了相同的请求,它每次都可以运行。

Am I doing something wrong? 难道我做错了什么? Any help would be great. 任何帮助都会很棒。

Thanks in advance. 提前致谢。

The error you're getting wasn't clear from the Question, that said: 问题中并没有明确您得到的错误,即:

I'm reasonably sure using localhost object URLs isn't going to work, you should test with a domain that's accessible by Facebook's crawler - the crawler needs to read the page and the meta tags on it to create the object in Facebook's graph 我有理由确定无法使用localhost对象URL,您应该使用Facebook的爬网程序可以访问的域进行测试-爬网程序需要读取页面及其上的meta标记才能在Facebook的图形中创建对象

Fixed the issue. 解决了该问题。 I was executing two post request simultaneously and this one would consistently keep failing, so I thought there was some problem with this request. 我正在同时执行两个发布请求,而这个请求始终会失败,因此我认为此请求存在一些问题。

FB.api('/me/Test:start .... );
FB.api('/me/feed .... );

I don't know what the problem was but when I separated these two requests. 我不知道问题出在什么地方,但是当我分开这两个请求时。 Everything worked as expected. 一切都按预期进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM