Answer the question
In order to leave comments, you need to log in
How to get information about a Facebook group by its address?
The input is the URL of the group, which does not contain its identifier. For example, https://www.facebook.com/groups/primorye/
How, having such an address and not having a user token (there is an application token), automatically get the group ID or information about the group (in the Graph API format )?
Answer the question
In order to leave comments, you need to log in
I found a dirty way: parse the identifier from the HTML code of the page on the main site https://www.facebook.com/groups/адрес_группы/
. And then get information about the group through the Graph API.
An example of getting the group ID in PHP:
function getGroupID( $name )
{
$url = 'https://www.facebook.com/groups/' . urlencode( $name ) . '/';
$curl = curl_init( $url );
curl_setopt( $curl, CURLOPT_TIMEOUT, 10 );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/601.7.7 (KHTML, like Gecko) Version/9.1.2 Safari/601.7.7" ); // Иначе Facebook не отдаст ответ
$html = curl_exec( $curl );
curl_close($curl);
if ( preg_match( '~"fb://group/(?:\?id=|.{0})([0-9]+)"~u', $html, $matches ) )
return (int)$matches[ 1 ];
if ( preg_match( '~"group_id"\s*:\s*([0-9]+)~u', $html, $matches ) )
return (int)$matches[ 1 ];
if ( preg_match( '~"/ajax/groups/membership[^"]+group_id=([0-9]+)"~u', $html, $matches ) )
return (int)$matches[ 1 ];
if ( preg_match( '~"/ajax/timeline/sign_up_dialog[^"]+entity_id=([0-9]+)["&;]~u', $html, $matches ) )
return (int)$matches[ 1 ];
return null;
}
var_dump( getGroupID( 'primorye' ) );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question