App\services\Lastfm::getSessionKey PHP Méthode

getSessionKey() public méthode

Get Last.fm's session key for the authenticated user using a token.
public getSessionKey ( string $token ) : string
$token string The token after successfully connecting to Last.fm
Résultat string The token key
    public function getSessionKey($token)
    {
        $query = $this->buildAuthCallParams(['method' => 'auth.getSession', 'token' => $token], true);
        try {
            $response = $this->get("/?{$query}", [], false);
            return (string) $response->session->key;
        } catch (Exception $e) {
            Log::error($e);
            return false;
        }
    }

Usage Example

Exemple #1
0
 /**
  * Serve the callback request from Last.fm.
  *
  * @param Request $request
  * @param Lastfm  $lastfm
  *
  * @return \Illuminate\Http\Response
  */
 public function callback(Request $request, Lastfm $lastfm)
 {
     abort_unless($token = $request->input('token'), 500, 'Something wrong happened.');
     // Get the session key using the obtained token.
     abort_unless($sessionKey = $lastfm->getSessionKey($token), 500, 'Invalid token key.');
     $this->auth->user()->savePreference('lastfm_session_key', $sessionKey);
     return view('api.lastfm.callback');
 }
All Usage Examples Of App\services\Lastfm::getSessionKey