original_string: public function upload(array $data)
  	{
  		$accessToken = $this->client->getAccessToken();
  
  		if (is_null($accessToken))
  		{
  			throw new \Exception('You need an access token to upload');
  		}
  
  		// Attempt to refresh the access token if it's expired and save the new one in the database
  		if ($this->client->isAccessTokenExpired())
  		{
  			$accessToken = json_decode($accessToken);
  			$refreshToken = $accessToken->refresh_token;
  			$this->client->refreshToken($refreshToken);
  			$newAccessToken = $this->client->getAccessToken();
  			$this->saveAccessTokenToDB($newAccessToken);
  		}
  
  		$snippet = new \Google_Service_YouTube_VideoSnippet();
  		if (array_key_exists('title', $data))
  		{
  			$snippet->setTitle($data['title']);
  		}
  		if (array_key_exists('description', $data))
  		{
  			$snippet->setDescription($data['description']);
  		}
  		if (array_key_exists('tags', $data))
  		{
  			$snippet->setTags($data['tags']);
  		}
  		if (array_key_exists('category_id', $data))
  		{
  			$snippet->setCategoryId($data['category_id']);
  		}
  
  		$status = new \Google_Service_YouTube_VideoStatus();
  		if (array_key_exists('status', $data))
  		{
  			$status->privacyStatus = $data['status'];
  		}
  
  		$video = new \Google_Service_YouTube_Video();
  		$video->setSnippet($snippet);
  		$video->setStatus($status);
  
  		$result = $this->youtube->videos->insert(
  			'status,snippet',
  			$video,
  			array(
  				'data'       => file_get_contents( $data['video']->getRealPath() ),
  				'mimeType'   => $data['video']->getMimeType(),
  				'uploadType' => 'multipart'
  			)
  		);
  
  		if (!($result instanceof \Google_Service_YouTube_Video))
  		{
  			throw new \Exception('Expecting instance of Google_Service_YouTube_Video, got:' . $result);
  		}
  
  		return $result->getId();
  
  	}
code: public function upload(array $data)
  	{
  		$accessToken = $this->client->getAccessToken();
  
  		if (is_null($accessToken))
  		{
  			throw new \Exception('You need an access token to upload');
  		}
  
  		// Attempt to refresh the access token if it's expired and save the new one in the database
  		if ($this->client->isAccessTokenExpired())
  		{
  			$accessToken = json_decode($accessToken);
  			$refreshToken = $accessToken->refresh_token;
  			$this->client->refreshToken($refreshToken);
  			$newAccessToken = $this->client->getAccessToken();
  			$this->saveAccessTokenToDB($newAccessToken);
  		}
  
  		$snippet = new \Google_Service_YouTube_VideoSnippet();
  		if (array_key_exists('title', $data))
  		{
  			$snippet->setTitle($data['title']);
  		}
  		if (array_key_exists('description', $data))
  		{
  			$snippet->setDescription($data['description']);
  		}
  		if (array_key_exists('tags', $data))
  		{
  			$snippet->setTags($data['tags']);
  		}
  		if (array_key_exists('category_id', $data))
  		{
  			$snippet->setCategoryId($data['category_id']);
  		}
  
  		$status = new \Google_Service_YouTube_VideoStatus();
  		if (array_key_exists('status', $data))
  		{
  			$status->privacyStatus = $data['status'];
  		}
  
  		$video = new \Google_Service_YouTube_Video();
  		$video->setSnippet($snippet);
  		$video->setStatus($status);
  
  		$result = $this->youtube->videos->insert(
  			'status,snippet',
  			$video,
  			array(
  				'data'       => file_get_contents( $data['video']->getRealPath() ),
  				'mimeType'   => $data['video']->getMimeType(),
  				'uploadType' => 'multipart'
  			)
  		);
  
  		if (!($result instanceof \Google_Service_YouTube_Video))
  		{
  			throw new \Exception('Expecting instance of Google_Service_YouTube_Video, got:' . $result);
  		}
  
  		return $result->getId();
  
  	}
code_tokens: public function upload ( array $ data ) { $ accessToken = $ this -> client -> getAccessToken ( ) ; if ( is_null ( $ accessToken ) ) { throw new \ Exception ( 'You need an access token to upload' ) ; } // Attempt to refresh the access token if it's expired and save the new one in the database if ( $ this -> client -> isAccessTokenExpired ( ) ) { $ accessToken = json_decode ( $ accessToken ) ; $ refreshToken = $ accessToken -> refresh_token ; $ this -> client -> refreshToken ( $ refreshToken ) ; $ newAccessToken = $ this -> client -> getAccessToken ( ) ; $ this -> saveAccessTokenToDB ( $ newAccessToken ) ; } $ snippet = new \ Google_Service_YouTube_VideoSnippet ( ) ; if ( array_key_exists ( 'title' , $ data ) ) { $ snippet -> setTitle ( $ data [ 'title' ] ) ; } if ( array_key_exists ( 'description' , $ data ) ) { $ snippet -> setDescription ( $ data [ 'description' ] ) ; } if ( array_key_exists ( 'tags' , $ data ) ) { $ snippet -> setTags ( $ data [ 'tags' ] ) ; } if ( array_key_exists ( 'category_id' , $ data ) ) { $ snippet -> setCategoryId ( $ data [ 'category_id' ] ) ; } $ status = new \ Google_Service_YouTube_VideoStatus ( ) ; if ( array_key_exists ( 'status' , $ data ) ) { $ status -> privacyStatus = $ data [ 'status' ] ; } $ video = new \ Google_Service_YouTube_Video ( ) ; $ video -> setSnippet ( $ snippet ) ; $ video -> setStatus ( $ status ) ; $ result = $ this -> youtube -> videos -> insert ( 'status,snippet' , $ video , array ( 'data' => file_get_contents ( $ data [ 'video' ] -> getRealPath ( ) ) , 'mimeType' => $ data [ 'video' ] -> getMimeType ( ) , 'uploadType' => 'multipart' ) ) ; if ( ! ( $ result instanceof \ Google_Service_YouTube_Video ) ) { throw new \ Exception ( 'Expecting instance of Google_Service_YouTube_Video, got:' . $ result ) ; } return $ result -> getId ( ) ; }
docstring: Uploads the passed video to the YouTube account identified by the access token in the DB and returns the
  uploaded video's YouTube Video ID. Attempts to automatically refresh the token if it's expired.
  
  @param array $data As is returned from \Input::all() given a form as per the one in views/example.blade.php
  @return string The ID of the uploaded video
  @throws \Exception
docstring_tokens: Uploads the passed video to the YouTube account identified by the access token in the DB and returns the uploaded video s YouTube Video ID . Attempts to automatically refresh the token if it s expired .