简体   繁体   中英

Posting custom Facebook Stories in javascript

I've been through the jungle of Facebook's antiquated documentation, looked all over google and all over stack overflow. There just seems to be something I'm not getting about posting a custom story using graph objects. I have an app which just a basic quiz i built in flash builder, it asks you 4 questions and gives you a score based on how many you got right. In the future i want to be able to publish a story on behalf of the user that indicates their score and directs them to the app.

However, I'm stuck on square one, which is publishing a custom story at all. Once i get over that hurdle i should be able to figure it out from there.

So, here's what I've got. I'm using flash builder to build a web app, which im hosting on my domain (an https domain). In the hmtl template, I'm setting meta-tag information for an object "Quiz", which is hosted on the domain as an index.html page. Here is my meta-tag information

<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# gqt_test: http://ogp.me/ns/fb/gqt_test#">
        <meta property="fb:app_id"      content="my app id" /> 
        <meta property="og:type"        content="getquiztool_test:quiz" /> 
        <meta property="og:url"         content="https://my domain.com/getquiztool/" /> 
        <meta property="og:title"       content="Sample Quiz" /> 
        <meta property="og:image"       content="https://my domain.com/getquiztool/game.png" /> 
        <meta property="gqt_test:score" content="Sample score" /> 

I am also loading the facebook SDK like this, which has worked for some of the simple code tests before, such as posting a like action .

(function(d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) return;
        js = d.createElement(s); js.id = id;
        js.src = "https://connect.facebook.net/en_US/sdk.js#xfbml=1&appId=258148224385655&version=v2.0";
        fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));

I've also created the custom story from the app page "Open Graph" section, using the action "Take" and the object "Quiz".

Here is what is working for me. These two buttons. The first allows the user to share the website as a link. The second was an attempt to do "feed-gaming", which I stopped working towards because I believe they've mostly stopped supporting it. It works as far as it lets you share a link to the site with the swf embedded in the post (but unable to be run).

<div class="fb-share-button" data-href="mydomain.com/app_namespace"></div>
    <button onclick="var obj = {
        method: 'feed',
        title: 'Test',
        link: 'mydomain.com/app_namespace'
        };

        function callback(response) {
        console.log(response);
        }

        FB.ui(obj, callback);"
        >Share me, please</button>

So the Facebook SDK is working on my domain. Here's what isnt working. Using the sample code they provided. I've changed this about a dozen times to like 5 different sets of code, so im not even sure what isn't working about each one.

function shareStatus()
    {
        FB.ui(
        {
            method: 'share_open_graph',
            action_type: 'getquiztool_test.quiz',
            action_properties: JSON.stringify(
            {
                object:'https://mydomain.com/app_namespace/',
            })
        }, function(response){});
    }

When I call this function, i get that the action type isnt valid from the facebook popup. Which, really, makes sense because thats an object and not an action. But I'm not sure what i should be calling in this function.

I have tried the code generated for me from Facebook, like so

FB.api(
  'me/gqt_test:take',
  'post',
  {
    quiz: "http://samples.ogp.me/258211017712709"
  },
  function(response) {
    // handle the response
  }
);

inside the shareStatus() function, but when i do that, i get nothing. No response, no error.

I'm sorry for the wall of text, but I just want it known that I'm not coming here after 5 minutes of frustration. This is about 3 days, probably 10 hours, of fiddling around with this, trying to learn the documentation and trying to get results. I have learned a lot, but none of it seems connected to me. Am i missing something?

The least I can ask for is a detailed tutorial you might know of, just a link. Like, step by step by tedious step. Because the facebook documentation just assumes you know how other parts of it works, and links bring you in circles and never explain things clearly or give examples.

So I figured it out. It was something super dumb, as I suspected. And, as always when I ask a question anywhere, it happened a few hours after. Although, the app namespace i needed to use was an abbreviation of my app's name, which i dont really remember setting myself (instead of something like "myappnamespace_test" it was "man_test", so my app namespace was abbreviated to MAN)

Here is the call that worked for me given that everything else was in place.

function shareStatus()
    {
        FB.ui(
        {
            method: 'share_open_graph',
            action_type: 'man_test:take',
            action_properties: JSON.stringify(
            {
                quiz:'https://mydomain.com/whereTheObjectWithMetaTagsIs',
            })
        }, function(response){});
    }

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