I cannot access the value of a form input in a FB.api() function

Asked

Viewed 54 times

2

I need to get the id of a group on facebook that is passed to me through a form, so I can access data from this group, but I can’t use this id in the FB.api() function, because the function does not recognize the value that is assigned to 'idgroup' by the user. Within the function FB.getLoginStatus() I can access this value, but not in the function FB.api().

Does anyone know how I can get this function to access this value? I’ve spent hours and hours trying but I can’t find a solution.

<script>

        function valor() {
            x = document.getElementById('idgroup').value;
            y = x.toString();
            return y;
        }
        window.fbAsyncInit = function () {
            FB.init({
                ...
            });
            FB.getLoginStatus(function (response) {
                if (response.status === 'connected') {                        
                    accessToken = response.authResponse.accessToken;
                    var token = accessToken.toString();
                    num = valor();
                    path = "/" + num + "?fields=feed&access_token=" + token;
                    FB.api(
                            path, function (response) {
                                for (var i = 0, l = response.feed.data.length; i < l; i++)
                                {
                                    alert(response.feed.data[i].message);
                                }
                            });

                    document.getElementById('status').innerHTML = 'conectado';
                } else {
                    document.getElementById('status').innerHTML = 'nao conectado';
                }
            });
        };

 </script>
    <form id="form" method="get"> 
        <input type="text" id="idgroup" name="idgroup">
        <input type="submit" value="enviar" onclick="window.fbAsyncInit()" >
    </form>
   <div id="status"></div>
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.