开发者

Posting to a Facebook wall using a single function

Overview:

I got a website that has sentences that people can post to Facebook, but in each sentence there are input boxes, which people can change the default value. Kind of like a digital "Mad Lib". Each line has a button which will post that line to Facebook.

Help with:

Having a single function to post the data of the button being pressed to Facebook. I could just name the function differently and add the variables, but it defeats the purpose of a function.

HTML

<div id="post1">
    <span>I like</span>
        <input name="post1_1" value="Tom" type="text" id="post1_1" />
    <span>I think she is</span><input name="post1_2" value="Nice" type="text" id="post1_2" />

    <a href="javascript:Post(post1)">POST NOW</a>
</div>

<div id="post2">
    <span>My website is</span>
    <input name="post2_1" value="Great" type="text" id="post2_1" />
    <a href="javascript:Post(post2)">POST NOW</a>
</div>

SCRIPT

function postonwall(post1, post2)
{
    var post1_1 = null;
    var post1_2 = null;
    var post2_2 = null;
    var post2_3 = null;

    var post1_1 = $("#post1_1").val();
    var post1 = "I like" + post1_1 + ". I think she is" + post1_2;

    var post2_1 = $('#post2_1').val();
开发者_开发问答    var post2 = "My website is" + post2_1;

    FB.api('/me/feed',
           'post',
           {
               message: post1,
               message: post2
           }, function(response) {
               if (!response || response.error) {
                   alert('Oops! User Denied Access');
               }
               else {
                   alert('Success: Content Published');
               }
           });
}


I don't know the FB API, but if you can post only one message per request, then you can create an array of messages and then loop through it to post.

var messages = [
     msg1, msg2, msg3
];

for(var i in messages){
    // here comes your code to post to facebook
}

This would be called when the user clicks a button. If this is not what you meant, please give us some more info so we can help :D

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜