I need to get the id of a group on facebook that is passed to me through a form, so that I can access data from that group, but I can not use that id in the FB.api () function, because the function does not recognize the value that is assigned to the 'idgroup' by the user. Within the FB.getLoginStatus () function I can access this value, but not in the FB.api () function.
Does anyone know how I can get this function to access this value? I've been trying for hours and hours but can not 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>