HTML and CSS Reference
In-Depth Information
protected function save_access_token( )
{
$token_uri = $this->get_access_token_uri($_GET['code']);
$response = $this->request_uri($token_uri);
// Parse the response
$params = array();
parse_str($response, $params);
if (isset($params['access_token'])) {
$_SESSION['access_token'] = $params['access_token'];
$this->access_token = $params['access_token'];
$this->logged_in = TRUE;
return TRUE;
}
return FALSE;
}
protected function request_uri(
$uri
)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);
return curl_exec($ch);
}
abstract protected function load_user_data();
abstract protected function load_user_profile_image();
}
First, let's look at
request_uri()
. this method accepts one parameter,
$uri
, which is the uRi to be requested. it
then initializes
cURL
, sets the uRi to request to
$uri
, tells
cURL
to return the output of the request, and sets the
timeout to an arbitrary, but reasonable, value of four seconds.
next, in
save_access_token()
, the token request uRi is loaded into
$token_uri
using
get_access_token_
uri()
and the value of
code
(that is presumed to have been passed in the query string). then the response from
$token_uri
is stored in
$response
after loading it with
request_uri()
.
the value in
$response
, unless there has been an error, will contain the access token in query string format.
using the
$params
array and
parse_str()
, the query string is broken into an associative array, in which we
check for
access_token
. if it's set, it's stored in both the object's properties and the session,
$logged_in
is set to
TRUE
, and the method returns
TRUE
; if not, the method returns
FALSE
to indicate failure.
Search WWH ::
Custom Search