Need Help with Facebook Api

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Need Help with Facebook Api

    Im currently using javascript to login to my app and update statuses, share link etc ..... everything works apart from im having trouble getting post to a group working..
    heres the basics of the script:
    PHP Code:
    <!DOCTYPE html>
    <
    html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
        <
    head>
            <
    meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
            <
    title>your-link.com</title>
        </
    head>
        <
    body>
            <
    div id="fb-root"></div>
            <
    script type="text/javascript">
                
    window.fbAsyncInit = function() {
                    
    FB.init({appId'(your app id)'statustruecookietruexfbmltrue}); //replace (your app id) with your app id :)

                    /* All the events registered */
                    
    FB.Event.subscribe('auth.login', function(response) {
                        
    // do something with response
                        
    login();
                    });
                    
    FB.Event.subscribe('auth.logout', function(response) {
                        
    // do something with response
                        
    logout();
                    });

                    
    FB.getLoginStatus(function(response) {
                        if (
    response.session) {
                            
    // logged in and connected user, someone you know
                            
    login();
                        }
                    });
                };
                (function() {
                    var 
    document.createElement('script');
                    
    e.type 'text/javascript';
                    
    e.src document.location.protocol +
                        
    '//connect.facebook.net/en_US/all.js';
                    
    e.async true;
                    
    document.getElementById('fb-root').appendChild(e);
                }());

                function 
    login(){
                    
    FB.api('/me', function(response) {
                        
    document.getElementById('login').style.display "block";
                        
    document.getElementById('login').innerHTML response.name " succsessfully logged in!";
                    });
                }
                function 
    logout(){
                    
    document.getElementById('login').style.display "none";
                }

                
    //stream publish method
                
    function streamPublish(namedescriptionhrefTitlehrefLinkuserPrompt){
                    
    FB.ui(
                    {
                        
    method'stream.publish',
                        
    message'',
                        
    attachment: {
                            
    namename,
                            
    caption'',
                            
    description: (description),
                            
    hrefhrefLink
                        
    },
                        
    action_links: [
                            { 
    texthrefTitlehrefhrefLink }
                        ],
                        
    user_prompt_messageuserPrompt
                    
    },
                    function(
    response) {

                    });

                }
                function 
    showStream(){
                    
    FB.api('/me', function(response) {
                        
    //console.log(response.id);
                        
    streamPublish(response.name'Some words here''hrefTitle''http://your-link.com'"Share your-link.com");
                    });
                }

                function 
    share(){
                    var 
    share = {
                        
    method'stream.share',
                        
    u'http://your-link.com/'
                    
    };

                    
    FB.ui(share, function(response) { console.log(response); });
                }


                function 
    fqlQuery(){
                    
    FB.api('/me', function(response) {
                         var 
    query FB.Data.query('select uid, name, hometown_location, sex, pic_square from user where uid={0}'response.id);
                         
    query.wait(function(rows) {
                           
                           
    document.getElementById('name').innerHTML =
                             
    'Your name: ' rows[0].name "<br/>" +
                             
    'Id is: '+rows[0].uid'<br/>'+
                             
    '<img src="' rows[0].pic_square '" alt="" />' "<br/>";
                         });
                    });
                }

                function 
    setStatus(){
                    
    status1 document.getElementById('status').value;
                    
    FB.api(
                      {
                        
    method'status.set',
                        
    statusstatus1
                      
    },
                      function(
    response) {
                        if (
    response == 0){
                            
    alert('Your facebook status not updated. Give Status Update Permission.');
                        }
                        else{
                            
    alert('Your facebook status updated');
                        }
                      }
                    );
                }
                var 
    response;
                function 
    post2group()
                {
                    var 
    statusx document.getElementById('status').value;
                   
    FB.api("/(groupid)/feed"'post', { //replace (groupid) with your group id you want to post to
                   
    method'status.set',
                   
    namestatusx,
                   
    linkstatusx
                   
    },
                   function(
    response) {
                     if (!
    response || response.error) {
                         
    alert('Error occured'+response.error);
                     } else {
                        
    alert('Post ID: ' response.id);
                     }
                   }
                );
        }
            </
    script>

            <
    h3>your-link.com</h3>
            <
    p><fb:login-button autologoutlink="true" perms="email,user_birthday,status_update,publish_stream,user_about_me"></fb:login-button></p>

            <
    p>
                <
    a href="#" onclick="showStream(); return false;">Publish Wall Post</a> |
                <
    a href="#" onclick="share(); return false;">Share With Your Friends</a> |
                <
    a href="#" onclick="fqlQuery(); return false;">FQL Query Example</a>
            </
    p>

            <
    textarea id="status" cols="50" rows="5"></textarea>
            <
    br/>
            <
    a href="#" onclick="post2group(); return false;">Post to group</a> |
            <
    a href="#" onclick="setStatus(); return false;">Update Status</a>

            <
    br/><br/><br/>
            <
    div id="login" style ="display:none"></div>
            <
    div id="name"></div>

        </
    body>
    </
    html
    Any help here would be much appreciated even if it post to group via javascript or jquery or php
    the error message from the post to group is returning as an object .... im not sure where im going wrong
    i cant find any good examples on google either

    #2
    I have found following on
    Facebook App - auto login so can update status (php SDK) - Stack Overflow

    I think Github hosted app allawys had a example with it

    Comment


      #3
      thanks still not quite what im looking for fb api examples seem to be hard to find..
      especially posting to groups

      Comment


        #4
        any of these any good?

        fb.api · graph-me &mdash; Facebook Read Eval Log Loop

        posting to friends wall using facebook javascript sdk - Stack Overflow

        Graph api & javascript base Facebook Connect tutorial | Thinkdiff.net

        javascript - Facebook - Posting to a Group page - Stack Overflow


        Edited:
        Or theres..



        https://developers.facebook.com/docs/reference/api - this one possibly needs to login into fb first. it kept asking me to sign in. (i dont have fb account)
        Last edited by Ghost; 15.05.12, 11:05.
        <?php
        include ('Ghost');
        if ($Post == true) {
        echo '

        sigpic
        alt='coding-talk.com!!' />';
        echo 'Sharing Is Caring!';
        } else {
        echo '

        alt='the username GHOST has been comprimised!' />';
        echo 'OMG SOMEBODY HELP ME!!';
        }
        ?>

        Comment


          #5
          thanks i will see if i can adapt the posting to friends wall link

          Comment


            #6
            Originally posted by something else View Post
            thanks i will see if i can adapt the posting to friends wall link
            your welcome mate.
            <?php
            include ('Ghost');
            if ($Post == true) {
            echo '

            sigpic
            alt='coding-talk.com!!' />';
            echo 'Sharing Is Caring!';
            } else {
            echo '

            alt='the username GHOST has been comprimised!' />';
            echo 'OMG SOMEBODY HELP ME!!';
            }
            ?>

            Comment

            Working...
            X