break; case 'download': downloadCaption($youtube, $captionId, $htmlBody); break; case 'delete': deleteCaption($youtube, $captionId, $htmlBody); break; default: # All the available methods are used in sequence just for the sake of an example. uploadCaption($youtube, $client, $videoId, $captionFile, $captionName, $captionLanguage, $htmlBody); $captions = listCaptions($youtube, $videoId, $htmlBody); if (empty($captions)) { $htmlBody .= "<h3>Can't get video caption tracks.</h3>"; } else { $firstCaptionId = $captions[0]['id']; updateCaption($youtube, $client, $firstCaptionId, $htmlBody, null); downloadCaption($youtube, $firstCaptionId, $htmlBody); deleteCaption($youtube, $firstCaptionId, $htmlBody); } } } catch (Google_Service_Exception $e) { $htmlBody .= sprintf('<p>A service error occurred: <code>%s</code></p>', htmlspecialchars($e->getMessage())); } catch (Google_Exception $e) { $htmlBody .= sprintf('<p>An client error occurred: <code>%s</code></p>', htmlspecialchars($e->getMessage())); } } $_SESSION['token'] = $client->getAccessToken(); } else { // If the user hasn't authorized the app, initiate the OAuth flow $state = mt_rand(); $client->setState($state);
echo json_encode($response); die; } $json = file_get_contents('php://input'); $data = json_decode($json); $headers = apache_request_headers(); $header = str_replace("Bearer ", "", $headers['Authorization']); $contentHeaders = explode(';', $headers['Content-Type'], 2); $JWT = new JWT(); try { $decoded_token = $JWT->decode($header, $key, array($alg)); if ($contentHeaders[0] != 'multipart/form-data') { if ($data->location === 'fetch_photos') { fetchPhotos($data, $db); } elseif ($data->location === 'update_caption') { updateCaption($data, $db); } elseif ($data->location === 'delete_photo') { deletePhoto($data, $db); } } elseif ($contentHeaders[0] == 'multipart/form-data') { $data = json_decode($_POST['data']); if ($data->location === 'insert_photos') { insertPhotos($data, $db); } } } catch (DomainException $e) { header_status(401); $response['status'] = 'Error'; $response['message'] = $e->getMessage(); echo json_encode($response); die;