From 2c7e033917b6595331aee7fd2edfdcf58a93bcc0 Mon Sep 17 00:00:00 2001 From: mika-nt28 Date: Wed, 8 Jun 2016 10:51:55 +0200 Subject: [PATCH] Add Function for create api Token --- Plex.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Plex.php b/Plex.php index bff6cb3..dc869d8 100644 --- a/Plex.php +++ b/Plex.php @@ -79,7 +79,29 @@ * @version 0.0.2.5 */ class Plex -{ +{ + protected Token; + public function getToken($username, $password) { + $host = "https://plex.tv/users/sign_in.json"; + $header = array( + 'Content-Type: application/xml; charset=utf-8', + 'Content-Length: 0', + 'X-Plex-Client-Identifier: 8334-8A72-4C28-FDAF-29AB-479E-4069-C3A3', + 'X-Plex-Product: PhpPlexAPI', 'X-Plex-Version: v1_00', ); + $process = curl_init($host); + curl_setopt($process, CURLOPT_HTTPHEADER, $header); + curl_setopt($process, CURLOPT_HEADER, 0); + curl_setopt($process, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); + curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password); + curl_setopt($process, CURLOPT_TIMEOUT, 30); + curl_setopt($process, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($process, CURLOPT_POST, 1); + curl_setopt($process, CURLOPT_RETURNTRANSFER, true); + $data = curl_exec($process); + $curlError = curl_error($process); + $json = json_decode($data, true); + $this->Token= $json['user']['authentication_token']; + } /** * A list of Plex server machines on the network. This is defined by the * instantiating software.