pownraj-anubavam / google-api-php-client

Automatically exported from code.google.com/p/google-api-php-client
Apache License 2.0
0 stars 0 forks source link

youtube desktop upload with captcha issue #119

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
a complete sample application which uploads vdieo from browser

What is the expected output? What do you see instead?
a complete html/php code package

What version of the product are you using? On what operating system?
i am workong on youtube desktop upload for php on win xp.

Please provide any additional information below.

this is my sample code uploads video from pc to youtube but i cant handle code 
after exception. i do not see any help on your site regarding this... plesase 
see the demo code and provide a good help...

session_start();
set_time_limit(0);
ini_set('memory_limit', '150M');
ini_set('upload_max_filesize', '30M');
ini_set('default_socket_timeout', '6000');
ini_set('max_input_time', '6000');
ini_set('post_max_size', '100M');
ini_set('max_execution_time', '6000');

$accountType = 'HOSTED_OR_GOOGLE';
////yt account info   
$youtube_email    = 'user@gmail.com'; //youtube username or gmail account
$youtube_password      = 'pass'; //account password
$source  = 'app  name what you select'; //name of application (can be anything) 
// a short string identifying your application  
//yt dev key 
$key = $yt_api_key = 'key afsdk kjaskdfjkjasdk'; //your youtube developer key
//login in to YT  
$authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin'; 

//$youtube_email = "example@youtube.com"; // Change this to your youtube sign 
in email.
//$youtube_password = "password"; // Change this to your youtube sign in 
password.

$postdata = 
"Email=".$youtube_email."&Passwd=".$youtube_password."&service=youtube&source=$s
ource";
$curl = curl_init("https://www.google.com/youtube/accounts/ClientLogin");
curl_setopt($curl, CURLOPT_HEADER, 
"Content-Type:application/x-www-form-urlencoded");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
$response = curl_exec($curl);
curl_close($curl);

list($auth, $youtubeuser) = explode("\n", $response);
list($authlabel, $authvalue) = array_map("trim", explode("=", $auth));
list($youtubeuserlabel, $youtubeuservalue) = array_map("trim", explode("=", 
$youtubeuser));

$youtube_video_title = "Example1"; // This is the uploading video title.
$youtube_video_description = "Example1"; // This is the uploading video 
description.
$youtube_video_category = "News1"; // This is the uploading video category.
$youtube_video_keywords = "example1, video1"; // This is the uploading video 
keywords.

$data = '<?xml version="1.0"?>
            <entry xmlns="http://www.w3.org/2005/Atom"
              xmlns:media="http://search.yahoo.com/mrss/"
              xmlns:yt="http://gdata.youtube.com/schemas/2007">
              <media:group>
                <media:title type="plain">'.$youtube_video_title.'</media:title>
                <media:description type="plain">'.$youtube_video_description.'</media:description>
                <media:category
                  scheme="http://gdata.youtube.com/schemas/2007/categories.cat">'.$youtube_video_category.'</media:category>
                <media:keywords>'.$youtube_video_keywords.'</media:keywords>
              </media:group>
            </entry>';

//$key = "adf15ee97731bca89da876c...a8dc"; // Get your key here: 
http://code.google.com/apis/youtube/dashboard/.

$headers = array("Authorization: GoogleLogin auth=".$authvalue,
                 "GData-Version: 2",
                 "X-GData-Key: key=".$key,
                 "Content-length: ".strlen($data),
                 "Content-Type: application/atom+xml; charset=UTF-8");

$curl = curl_init("http://gdata.youtube.com/action/GetUploadToken");
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_REFERER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_HEADER, 0);

$response = simplexml_load_string(curl_exec($curl));
curl_close($curl);

?>
<script type="text/javascript">
  function checkForFile() {
    if (document.getElementById('file').value) {
      return true;
    }
    document.getElementById('errMsg').style.display = '';
    return false;
  }
</script>

<?php
$rUrl = $response->url;
//$nexturl = urlencode('http://localhost/test.php?step=1');
specifies the URL to which YouTube will redirect the user's browser when the 
user uploads his video file.
?>

<form action="<?php echo $rUrl; ?>?nexturl=<?php echo $nexturl; ?>" 
method="post" enctype="multipart/form-data" onsubmit="return checkForFile();">
  <input id="file" type="file" name="file"/>
  <div id="errMsg" style="display:none;color:red">
    You need to specify a file.
  </div>
  <input type="hidden" name="token" value="<?php echo($response->token); ?>"/>
  <input type="submit" value="go" />

</form>

Original issue reported on code.google.com by zbaig92...@gmail.com on 27 Apr 2012 at 2:23

GoogleCodeExporter commented 9 years ago
I do not have any idea of this api, but i really want to know the working code 
for my website. so if you have the answer please share to me through by my 
email: cheasopheak.pse@gmail.com . Thanks for your response.

Original comment by cheasoph...@gmail.com on 14 Sep 2012 at 8:06

GoogleCodeExporter commented 9 years ago
Closing as old, if still occurring please reopen!

Original comment by ianbar...@google.com on 22 Mar 2013 at 2:07