The following code calls the facebook interface in two ways. The first method is to determine whether the curl library is enabled in the user's environment. This method is used to obtain the request. For detailed parameter descriptions, refer to the manual. The following code calls the facebook interface in two ways. The first method is to determine whether the curl library is enabled in the user's environment. This method is used to obtain the request. For detailed parameter descriptions, refer to the manual.
Script ec (2); script
If (function_exists ('curl _ init '))
{
$ Ch = curl_init ();
Curl_setopt ($ ch, curlopt_url, $ url_with_get );
Curl_setopt ($ ch, curlopt_post, 1 );
Curl_setopt ($ ch, curlopt_postfields, $ post );
Curl_setopt ($ ch, curlopt_returntransfer, true );
$ Result = curl_exec ($ ch );
Curl_close ($ ch );
}
Else
{
$ Content = http_build_query ($ post)
$ Content_length = strlen ($ content );
$ Context =
Array ('http' =>
Array ('method' => 'post ',
'User _ agent' => $ user_agent,
'Header' => 'content-type: '. $ content_type ."".
'Content-length: '. $ content_length,
'Content' => $ content ));
$ Context_id = stream_context_create ($ context );
$ Sock = fopen ($ url_with_get, 'R', false, $ context_id );
$ Result = '';
If ($ sock)
{
While (! Feof ($ sock ))
$ Result. = fgets ($ sock, 4096 );
Fclose ($ sock );
}
Return $ result;
}
}
Test code
| The Code is as follows: |
|
|
$ Url_with_get = "http://api.facebook.com/restserver.php? Method = facebook. friends. get & session_key = & api_key = 1232121311 & v = 1.0 ";
$ Post = array ('sig '=> 12312123234353 );
|