Php file streams simulate POST and GET values. If we develop socialgame on facebook, we need to call its interface to obtain information about friends on facebook. At this time, we need to access an address provided by facebook. of course, if we develop social game on facebook, we need to call its interface to obtain information about friends of users on facebook. At this time, we need to access an address provided by facebook. of course, when you access him, he needs to verify your access to prevent illegal requests. At this time, you have to post to it | get some parameters.
Address:
$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);
How to get data from this address and briefly introduce the following code of the terminal:
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 . "\r\n" . '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; }}
The above code uses two methods to call the facebook interface. 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. Note that we usually need to obtain the returned result of calling the interface, so we need to set the value of CURLOPT_RETURNTRANSFER to return the result to the variable.
The second method is to convert the url request into a file stream for processing.
Alibaba game, which needs to be called to obtain information about friends on facebook. At this time, we need to access an address provided by facebook. of course...