简体   繁体   中英

Facebook application : auto-publish post to wall

I have a facebook app and trying to publish a post to user's wall, without notyfing the user with any kind of pop-up dialog (for users have granded the publish_stream oauth permission).

I've been searching a lot, and tried many different things, used FB.ui or FB.api, but i can't get it to work properlly, i either get the pop-up notification, or nothing at all.

Following the answer here , i have this code, but it just does nothing, it just alerts "undefined" (as the post didn't get published, there is no post_id)

var publish = {
     method: 'stream.publish',
     message: 'Test Message',
     picture : 'http://www.mydomain.gr/apps/app1/img/small.png',
     link : 'http://www.mydomain.gr/apps/app1/',
     name: 'THIS IS MY APPLICATION!',
     caption: ' ',
     description: 'I just used this app and i loved it!!',
     actions : { name : 'Use me!', link : 'http://www.mydomain.gr/apps/app1/'}
   };

   FB.api('/me/feed', 'POST', publish, function(response) {  
      alert(responce.post_id)
   });

Any ideas how i can achieve it? Thanks in advance.

What you are trying to do is against Facebook rules!

Each message you want to post to a user wall has to be seen first by the user and approved. Read the Facebook platform policy and pay attention to Section IV paragraph 3.

You need to get the actions approved by Facebook first.

Read more here : https://developers.facebook.com/docs/opengraph/using-actions/

Let me try to explain you a scenario:

The Facebook APIs provides developers many integrations, so apps can offer users a customized interface so a unique experience. So, the call you are trying to make can be used inside your app, if you have a sequential user experience, that allows users to publish something, so users need to click something or finish something, save something, or even, read something, like something, inside your custom interface.

About FB.ui or FB.api, I'm sure you should use FB.ui, so you can trigger a dialog, for publishing something like that, you need. Also can have a callback, so you can track return.

For example:

/* make the API call */
FB.api(
    "/me/games.plays",
    "POST",
    {
        "game": "http:\/\/samples.ogp.me\/163382137069945"
    },
    function (response) {
      if (response && !response.error) {
        /* handle the result */
      }
    }
);

From: https://developers.facebook.com/docs/reference/opengraph/action-type/games.plays/

<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# game: http://ogp.me/ns/game#">
<meta property="fb:app_id"   content="302184056577324" /> 
<meta property="og:type"     content="game.achievement" /> 
<meta property="og:url"      content="Put your own URL to the object here" /> 
<meta property="og:title"    content="Sample Game Achievement" /> 
<meta property="og:image"    content="https://s-static.ak.fbcdn.net/images/devsite/attachment_blank.png" /> 
<meta property="game:points" content="Sample Points" />`

From: https://developers.facebook.com/docs/reference/opengraph/object-type/game.achievement/

Custom Open Graph stories are unfortunately deprecated after Graph API 2.8. Graph API 2.7.

Actions fields also deprecated.

In 2017 - 2018 you have to set Open Graph metadata on your link, so you can customize published posts like mentioned before.

I think today Facebook provides better methods to make that many apps tried to do sometime ago, instead of publishing many posts, making actions, I think Facebook can make all internet sites and apps more interactive and social.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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