本文整理匯總了PHP中OAuth\OAuth2\Token\StdOAuth2Token::setLifeTime方法的典型用法代碼示例。如果您正苦於以下問題:PHP StdOAuth2Token::setLifeTime方法的具體用法?PHP StdOAuth2Token::setLifeTime怎麽用?PHP StdOAuth2Token::setLifeTime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類OAuth\OAuth2\Token\StdOAuth2Token
的用法示例。
在下文中一共展示了StdOAuth2Token::setLifeTime方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: parseAccessTokenResponse
protected function parseAccessTokenResponse($responseBody)
{
if (version_compare($this->apiVersion, 'v2.2', '>') === true) {
$data = json_decode($responseBody, true);
} else {
parse_str($responseBody, $data);
}
if (null === $data || !is_array($data)) {
throw new TokenResponseException('Unable to parse response.');
} elseif (isset($data['error'])) {
if (is_array($data['error']) === true) {
$errorMessage = $data['error']['message'];
} else {
$errorMessage = $data['error'];
}
throw new TokenResponseException('Error in retrieving token: "' . $errorMessage . '"');
}
$token = new StdOAuth2Token();
$token->setAccessToken($data['access_token']);
if (isset($data['expires'])) {
$token->setLifeTime($data['expires']);
}
if (isset($data['refresh_token'])) {
$token->setRefreshToken($data['refresh_token']);
unset($data['refresh_token']);
}
unset($data['access_token']);
unset($data['expires']);
$token->setExtraParams($data);
return $token;
}
示例2: parseAccessTokenResponse
/**
* @param string $responseBody
* @return \OAuth\Common\Token\TokenInterface|\OAuth\OAuth2\Token\StdOAuth2Token
* @throws \OAuth\Common\Http\Exception\TokenResponseException
*/
protected function parseAccessTokenResponse($responseBody)
{
$data = json_decode($responseBody, true);
if (null === $data || !is_array($data)) {
throw new TokenResponseException('Unable to parse response.');
} elseif (isset($data['error'])) {
throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
}
$token = new StdOAuth2Token();
$token->setAccessToken($data['access_token']);
$token->setLifeTime($data['expires_in']);
if (isset($data['refresh_token'])) {
$token->setRefreshToken($data['refresh_token']);
unset($data['refresh_token']);
}
unset($data['access_token']);
unset($data['expires_in']);
$token->setExtraParams($data);
return $token;
}
示例3: parseAccessTokenResponse
/**
* {@inheritdoc}
*/
protected function parseAccessTokenResponse($responseBody)
{
// Facebook gives us a query string ... Oh wait. JSON is too simple, understand ?
parse_str($responseBody, $data);
if (null === $data || !is_array($data)) {
throw new TokenResponseException('Unable to parse response.');
} elseif (isset($data['error'])) {
throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
}
$token = new StdOAuth2Token();
$token->setAccessToken($data['access_token']);
$token->setLifeTime($data['expires']);
if (isset($data['refresh_token'])) {
$token->setRefreshToken($data['refresh_token']);
unset($data['refresh_token']);
}
unset($data['access_token']);
unset($data['expires']);
$token->setExtraParams($data);
return $token;
}
示例4: parseAccessTokenResponse
/**
* @param string $responseBody
* @return StdOAuth2Token
* @throws TokenResponseException
*/
protected function parseAccessTokenResponse($responseBody)
{
$data = $this->service->parseAccessTokenResponse($responseBody);
if (!isset($data) || !is_array($data)) {
throw new TokenResponseException('Unable to parse response.');
}
$error = $this->service->getAccessTokenResponseError($data);
if (isset($error)) {
throw new TokenResponseException('Error in retrieving token: "' . $error . '"');
}
$token = new StdOAuth2Token();
$names = $this->service->getAccessTokenArgumentNames();
$token->setAccessToken($data[$names['access_token']]);
unset($data[$names['access_token']]);
if (isset($data[$names['expires_in']])) {
$token->setLifeTime($data[$names['expires_in']]);
unset($data[$names['expires_in']]);
} else {
$token->setLifetime($this->service->getTokenDefaultLifetime());
}
if (isset($data[$names['refresh_token']])) {
$token->setRefreshToken($data[$names['refresh_token']]);
unset($data[$names['refresh_token']]);
}
$token->setExtraParams($data);
return $token;
}
示例5: parseAccessTokenResponse
/**
* {@inheritdoc}
*/
protected function parseAccessTokenResponse($responseBody)
{
// Facebook gives us a query string on old api versions
if (0 !== strpos($responseBody, '{')) {
parse_str($responseBody, $data);
} else {
$data = json_decode($responseBody, true);
}
if (null === $data || !is_array($data)) {
throw new TokenResponseException('Unable to parse response.');
} elseif (isset($data['error'])) {
throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
} elseif (empty($data['access_token'])) {
throw new TokenResponseException('Error in retrieving token: Access token is empty!');
}
$token = new StdOAuth2Token();
$token->setAccessToken($data['access_token']);
if (isset($data['expires'])) {
$token->setLifeTime($data['expires']);
}
if (isset($data['refresh_token'])) {
$token->setRefreshToken($data['refresh_token']);
unset($data['refresh_token']);
}
unset($data['access_token']);
unset($data['expires']);
$token->setExtraParams($data);
return $token;
}
示例6: parseAccessTokenResponse
/**
* {@inheritdoc}
*/
protected function parseAccessTokenResponse($responseBody)
{
parse_str($responseBody, $data);
if (null === $data || !is_array($data) || empty($data)) {
throw new TokenResponseException('Unable to parse response.');
} elseif (isset($data['error'])) {
throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
} elseif (isset($data['error_reason'])) {
throw new TokenResponseException('Error in retrieving token: "' . $data['error_reason'] . '"');
}
$token = new StdOAuth2Token();
$token->setAccessToken($data['access_token']);
$token->setLifeTime($data['expires']);
// I hope one day Deezer add a refresh token :)
if (isset($data['refresh_token'])) {
$token->setRefreshToken($data['refresh_token']);
unset($data['refresh_token']);
}
unset($data['access_token']);
unset($data['expires']);
$token->setExtraParams($data);
return $token;
}