Deleting a previosly posted Article with OpenGraph

2020-07-25 01:20发布

问题:

I've created a simple app for reading articles, which creates posts with the following code:

  FB.api('/me/[NAMESPACE]:read&article=http://example.com/article.html','post', function(response) {

                 if (!response) { 
                      alert('Error Occurred I got no response with ' + $pageURL);
                 }
                 else if (response.error) {
                      alert('Error Occurred' + response.responseText + " " + response.error.responseText);
                 } else {
                     alert('Post was successful! Action ID: ' + response.id);
                     var idToDeleteLater = response.id;
                 }
         });

And I want to be able to check if the page had been visited before, so I'll be able to forbid any further creating of posts for the same article.

But in order to do that I'd need to get the article ID, and I haven't been able to get to it with the response.id command, since that one only gives me the ID of the individual post.

I don't want to use the given method:

  function postUnreadSpecific()
  {
  var postId = idToDeleteLater;

  FB.api(postId, 'delete', function(response) {
  if (!response || response.error) {
    alert('Error occured');
  } else {
    alert('Post was deleted');
  }
});

Because the reading is done via a Button (same as in the tutorial with the cooking), so whenever I push the button new posts are created, with different ID's and I obviously don't wan't to type them manually.

So, bottomline, how does one get the page ID (not the post ID with response.id), and make a check, if the page had been visited before, disable creation of new posts...

回答1:

Facebook Open Graph actions have the option of being unique. This setting is on the action creation page under "Configure Story Attachment" hidden under the "Advanced Settings" link. In there you will find a toggle called "Unique Action" which can be set to "Allow only once." This ensures that there will only be one "action-object" pair per user.

Note that you need to do this when you set up the action, as actions cannot be edited after they are approved.