Recently developed social game, found that the use of this thing is still relatively ordinary, here to make a summary, one for their own memory, but also hope that everyone has help.
First look at the demand, if we develop social game on Facebook, we need to call its interface to get the user's friend information on Facebook. At this point we're going to visit an address provided by Facebook, and of course when you visit him, he needs to verify your visit and prevent illegal requests. At this point you have to post|get some parameters to it.
As the following address:
Copy the Code code as follows:
$url _with_get= "Http://api.facebook.com/restserver.php?method=facebook.friends.get&sessi
$post = Array (' sig ' =>12312123234353);
How to get data from this address, simply introduce the following code:
Copy the Code code as follows:
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 ways to tune the interface of Facebook, the first county to determine whether the user's environment opens the Curl Library, opened the library, in this way to obtain the request. Inside the detailed parameters explained that you can refer to the manual.
It is suggested here that since we usually need to get the return result of the calling interface, we want to set the value of Curlopt_returntransfer and return the result to the variable.
The second approach is intuitive, translating URL requests into file streams for processing.
The above describes the proactive system password Reco PHP simulation post| Get operation implementation code, including the proactive system password Reco aspects of the content, I hope to be interested in PHP tutorial friends helpful.