YouTube upload form entries with PHP/XML - youtube

I have a script for YouTube which allows me or anyone else to use on a site to upload videos directly to a YouTube account.
The problem is only the video is uploaded with no video information such as title & description I want the person who is uploading the video to have the options of filling in a form which will then result in the title & description on YouTube.
The script can be seen at the bottom. What I want is for a form to be in place which is something like the following:
Video Title: Cat Drives Car
Video By: MrShoez
Video Description: Watch this video of a cat driving a car.
And the title output would be something as "Cat Drives Car by MrShoez"
Along with the description displaying: This video was submitted on DATE HERE by MrShoez. "Watch this video of a cat driving a car."
*
<?php
$youtube_email = "email#address.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=Example";
$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 = "VIDEO TITLE"; // This is the uploading video name.
$youtube_video_description = "VIDEO DESCRIPTION"; // This is the uploading video description.
$youtube_video_category = "CATEGORY"; // This is the uploading video category.
$youtube_video_keywords = "tags, tags, tags, tags"; // 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>
<yt:private/>
<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 = "UNIQUEKEY HERE"; // 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
$nexturl = "http://website.com/directurl"; // This parameter specifies the URL to which YouTube will redirect the user's browser when the user uploads his video file.
?>
<form action="<?php echo($response->url); ?>?nexturl=<?php echo(urlencode($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>
</php>
*

Related

Call php function onclick button in same page

Once I select check boxes & OnClick Insert Button I am calling php function present in api.php page to display results under status column.
But its not fetching any results .
below is api url page results :
table.php - php code
<p><button type= "button" id="show_status" >Show Status</button></p>
<table class="tbl-qa" border="1">
<thead>
<tr>
<th class="table-header">ID</th>
<th class="table-header">ORDERID</th>
<th class="table-header">Status</th>
</tr>
</thead>
<tbody id="table-body">
<?php
if(!empty($orderrecords))
{
foreach($orderrecords as $k=>$v)
{?>
<tr class="table-row" id="table-row-<?php echo $orderrecords[$k]["id"]; ?>" tabindex="<?php echo $tabindex;?>">
<td>
<input type="checkbox" name="assigneeid" class="assigneeid-order" value="<?php echo $orderrecords[$k]["order_id"]; ?>">
</td>
<td><?php echo $orderrecords[$k]["order_id"]; ?></td>
<td id="<?php echo checkecomstatus($orderrecords[$k]["order_id"]);?>"></td>
</tr>
<?php
$tabindex++;
}
}?>
</tbody>
</table>
<input type="hidden" name="ordercheckallIDs" id="ordercheckallIDs" value="<?php echo $ordercheckall;?>"/>
table.php - javascript code
$('#show_status').click(function(){
var selected = [];
$('.assigneeid-order input:checked').each(function() {
selected.push($(this).val());
});
var jsonString = JSON.stringify(selected);
$.ajax({
type: "POST",
url: "api.php",
data: {data : jsonString},
success: function(response){
$.each(response, function(index, val) {
$("#"+index+"").html(val);
});
}
});
});
function assignallorderids()
{
var checkstatus=$("#checkall").is(":checked");
if(checkstatus==true)
{
var id=document.getElementById("ordercheckallIDs").value;
document.getElementById("orderids").value=id;
$("input:checkbox[name='checkassigneeid']").prop('checked',true);
}
else
{
$("input:checkbox[name='checkassigneeid']").prop('checked',false);
document.getElementById("orderids").value='';
}
}
function assignorderids(oid)
{
var checkstatus=$("#assigneeid-"+oid).is(":checked");
var morderId =document.getElementById("orderids").value;
if(checkstatus==false)
{
var arrayorder = JSON.parse("[" + morderId + "]");
document.getElementById("orderids").value='';
for (var i = 0; i < arrayorder.length; i++) {
var orderstatusValue=arrayorder[i];
if(orderstatusValue!=oid){
if (document.getElementById("orderids").value=='')
{
document.getElementById("orderids").value=orderstatusValue;
}
else
{
var newvalue=document.getElementById("orderids").value;
document.getElementById("orderids").value=newvalue+","+orderstatusValue;
}
}
}
}
else
{
if(morderId=='')
{
document.getElementById("orderids").value=oid;
}
else
{
document.getElementById("orderids").value=morderId+","+oid;
}
}
}
api.php
<?php
$curl_data['username']='outthinking781346';
$curl_data['password']='ouhk78epe34csmed46d';
$data = json_decode(stripslashes($_POST['data']));
foreach($data as $id){
$orderid = $id;
$curl_data['awb']=$orderid;
$response = array();
$url = 'plapi.ecomexpress.in/track_me/…'.$orderid.'&username=outthinking781346&password=ouhk78epe34csmed46d';
$ch = curl_init();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curl_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$output = curl_exec ($ch);
curl_close($ch);
$res = explode("\n",$output);
if ( ! isset($res[13]))
{
$res[13] = null;
}
$status = str_replace('</field>.','',$res[13]);
$statusfinal = str_replace('<field type="CharField" name="status">','',$status);
if($statusfinal!='')
{
$sqlecom = "UPDATE do_order set in_transit='".$statusfinal.".',tconformed_by='Ecom' where order_id=".$orderid;
$db_handleecom = new DBController();
$resultecom = $db_handleecom->executeUpdate($sqlecom);
}
// store the responce in array
$response[$orderid] = $statusfinal;
return $response;
}
?>
table.php:
<td>
<input type="checkbox" name="assigneeid" class="assigneeid-order" value="<?php echo $orderrecords[$k]["order_id"]; ?>">
</td>
<td>
<?php echo $orderrecords[$k]["order_id"]; ?>
</td>
<td id="<?php echo $orderrecords[$k]["order_id"];?>">
</td>
in ajax call:
$('#show_status').click(function(){
var selected = [];
$('.assigneeid-order:checked').each(function() {
selected.push($(this).val());
});
var jsonString = JSON.stringify(selected);
$.ajax({
type: "POST",
url: "api.php",
data: {data : jsonString},
success: function(response){
response = $.parseJSON(response);
$.each(response, function(index, val) {
$("#"+index+"").html(val);
});
}
});
api.php:
require_once("dbcontroller.php");
$db_handle = new DBController();
$curl_data['username']='outthinking781346';
$curl_data['password']='ouhk78epe34csmed46d';
$data = json_decode(stripslashes($_POST['data']));
$response = array();
foreach($data as $id){
$orderid = $id;
$curl_data['awb']=$orderid;
$url = 'https://plapi.ecomexpress.in/track_me/api/mawbd/?awb=awbnumber&order='.$orderid.'&username=outthinking781346&password=ouhk78epe34csmed46d';
$ch = curl_init();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curl_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$output = curl_exec ($ch);
curl_close($ch);
$res = explode("\n",$output);
if ( ! isset($res[13]))
{
$res[13] = null;
}
$status = str_replace('</field>','',$res[13]);
$statusfinal = str_replace('<field type="CharField" name="status">','',$status);
if($statusfinal!='')
{
$sqlecom = "UPDATE do_order set in_transit='".$statusfinal.".',tconformed_by='Ecom' where order_id=".$orderid;
$db_handleecom = new DBController();
$resultecom = $db_handleecom->executeUpdate($sqlecom);
}
// store the responce in array
$response[$orderid] = $statusfinal;
}
echo json_encode($response);
//return $response;

How to get the twitter card data form twitter

How we get the twitter card data from twitter when we get the twits.
my code is
libxml_use_internal_errors(true);
$page_html = new DomDocument();
$ch = curl_init();
$timeout = 500;
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
if(!empty($data)){
$page_html->loadHTML($data);
}
It is not possible to get Twitter Card data from the API.

Google+ oauth / 0auth API: How can I prevent redirection by google-signin2 button?

I am just learning the basics of Google´s API 0auth authentication sign-in system.
I'm using this tutorial found on CodexWorld. Although this one worked out, it uses an ugly picture instead of a "real" google sign-in button (from the g-signin2 class), and that´s something I personally just can´t get over.
I tried replaced the picture with that button and added the required metas to work with it. But now it opened 2 windows, not only 1 through the php.
How can i prevent the second window, opened by the g-signin2-button, from opening?
Thanks for all your help!
VicStudio
Here´s the modified code by me. Notice how I replaced the picture button with a real google-signin2 button and added the required metas.
<?php
//Include GP config file && User class
include_once 'gpConfig.php';
include_once 'classuser.php';
if(isset($_GET['code'])){
$gClient->authenticate($_GET['code']);
$_SESSION['token'] = $gClient->getAccessToken();
header('Location: ' . filter_var($redirectURL, FILTER_SANITIZE_URL));
}
if (isset($_SESSION['token'])) {
$gClient->setAccessToken($_SESSION['token']);
}
if ($gClient->getAccessToken()) {
//Get user profile data from google
$gpUserProfile = $google_oauthV2->userinfo->get();
//Initialize User class
$user = new User();
//Insert or update user data to the database
$gpUserData = array(
'oauth_provider'=> 'google',
'oauth_uid' => $gpUserProfile['id'],
'email' => $gpUserProfile['email'],
'link' => $gpUserProfile['link']
);
$userData = $user->checkUser($gpUserData);
//Storing user data into session
$_SESSION['userData'] = $userData;
//Render facebook profile data
if(!empty($userData)){
$output = '<h1>Google+ Profile Details </h1>';
$output .= '<br/>Google ID : ' . $userData['oauth_uid'];
$output .= '<br/>Email : ' . $userData['email'];
$output .= '<br/>Logged in with : Google';
$output .= '<br/>Click to Visit Google+ Page';
$output .= '<br/>Logout from Google';
}else{
$output = '<h3 style="color:red">Some problem occurred, please try again.</h3>';
}
} else {
//New, modified code:
$authUrl = $gClient->createAuthUrl();
$authUrl = filter_var($authUrl, FILTER_SANITIZE_URL);
$output = "<div class='g-signin2' data-onsuccess='onSignIn' id='glog'></div> <script>document.getElementById('glog').onclick = function () { window.location.href = '".$authUrl."'; } </script>";
//Original Code:
// $authUrl = $gClient->createAuthUrl();
// $output = '<img src="images/glogin.png" alt=""/>';
}
?>
<html>
<head>
<meta name="google-signin-scope" content="profile email">
<meta name="google-signin-client_id" content="246194741577-gajd75di0cam2j9u4q69l9trvg88hqkc.apps.googleusercontent.com">
<script src="https://apis.google.com/js/platform.js" async defer></script>
</head>
<body>
<div><?php echo $output; ?></div>
</body>
</html>

Prestashop API upload image error PHP 5.6

It's simple, but for me this is not simple. I use PHP 5.6.
This works:
<form method="post" action="http://RUSRRJIZ3A2WRL.....ML1IU6D9G#host.localhost/api/images/products/88" enctype="multipart/form-data" >
<input type='file' name='image' />
<button type="submit" >send</button>
</form>
But this not:
$id_product = 88;
$cfile = curl_file_create('bigimage.jpg','image/jpeg','bigimage');
$data = array('image' => $cfile);
$header = array('Content-Type: multipart/form-data');
$url = PS_SHOP_PATH . "api/images/products/$id_product";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
curl_setopt($ch, CURLOPT_USERPWD, PS_WS_AUTH_KEY.':');
//curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '#'.realpath('bigimage.jpg').";type=jpeg"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if(!$result = curl_exec($ch)) throw new Exception('curl_exec generate an error.');
curl_close($ch);
Can anyone help me? Maybe it can be a security error? Only error 500 is sometimes shown in log.
For me I use :
// envois de la nouvelle image
$url = PS_SHOP_PATH. "/api/images/products/".$product->id;
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, PS_WS_AUTH_KEY.':');
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '#'.$image_path . ";type=" . $image_mime));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
Thanks for posting your code :
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
Without it my upload fails with ERROR 500.
Thnaks again !

importing gmail contacts using php

May be am creating a lot of confusion with the previous post, so am trying redesign my entire post with my requirement and effort.
I want to fetch GMAIL contact list using PHP, to achieve this I have done the following thing:
Create Google Client ID with oAuth 2.0 protocol
Create 2 PHP files (oAuth.php and index.php)
Here is the code for 2 files:
oAuth.php:
<html>
<head>
<meta name="robots" content="noindex" />
<title>Email address list - Import Gmail or Google contacts</title>
<style type="text/css">
a:link {color:Chocolate;text-decoration: none;}
a:hover {color:CornflowerBlue;}
.logo{width:100%;height:110px;border:2px solid black;background-color:#666666;}
</style>
</head>
<body>
<div class="logo" >
</div>
<br/>
<div><b>Visit Tutorial: </b><a style="font-size:17px;" href="" >Import Gmail or Google contacts using Google Contacts Data API 3.0 and OAuth 2.0 in PHP</a></div>
<br/>
<div style="padding-left: 50px;">
<?php
$client_id = '1041526369396-kmnbhsos616eqcqimjrs07icn2c176ln.apps.googleusercontent.com';
$client_secret = '*************';
$redirect_uri = 'https://www.test.multicon.in/test9/oauth.php';
$max_results = 25;
$auth_code = $_GET["code"];
function curl_file_get_contents($url)
{
$curl = curl_init();
$userAgent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';
curl_setopt($curl,CURLOPT_URL,$url); //The URL to fetch. This can also be set when initializing a session with curl_init().
curl_setopt($curl,CURLOPT_RETURNTRANSFER,TRUE); //TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
curl_setopt($curl,CURLOPT_CONNECTTIMEOUT,5); //The number of seconds to wait while trying to connect.
curl_setopt($curl, CURLOPT_USERAGENT, $userAgent); //The contents of the "User-Agent: " header to be used in a HTTP request.
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); //To follow any "Location: " header that the server sends as part of the HTTP header.
curl_setopt($curl, CURLOPT_AUTOREFERER, TRUE); //To automatically set the Referer: field in requests where it follows a Location: redirect.
curl_setopt($curl, CURLOPT_TIMEOUT, 10); //The maximum number of seconds to allow cURL functions to execute.
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); //To stop cURL from verifying the peer's certificate.
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
$contents = curl_exec($curl);
curl_close($curl);
return $contents;
}
$fields=array(
'code'=> urlencode($auth_code),
'client_id'=> urlencode($client_id),
'client_secret'=> urlencode($client_secret),
'redirect_uri'=> urlencode($redirect_uri),
'grant_type'=> urlencode('authorization_code')
);
$post = '';
foreach($fields as $key=>$value) { $post .= $key.'='.$value.'&'; }
$post = rtrim($post,'&');
$curl = curl_init();
curl_setopt($curl,CURLOPT_URL,'https://accounts.google.com/o/oauth2/token');
curl_setopt($curl,CURLOPT_POST,5);
curl_setopt($curl,CURLOPT_POSTFIELDS,$post);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);
$result = curl_exec($curl);
curl_close($curl);
$response = json_decode($result);
$accesstoken = $response->access_token;
$url = 'https://www.google.com/m8/feeds/contacts/default/full?max-results='.$max_results.'&oauth_token='.$accesstoken;
$xmlresponse = curl_file_get_contents($url);
if((strlen(stristr($xmlresponse,'Authorization required'))>0) && (strlen(stristr($xmlresponse,'Error '))>0))
{
echo "<h2>OOPS !! Something went wrong. Please try reloading the page.</h2>";
exit();
}
echo "<h3>Email Addresses:</h3>";
$xml = new SimpleXMLElement($xmlresponse);
$xml->registerXPathNamespace('gd', 'http://schemas.google.com/g/2005');
$result = $xml->xpath('//gd:email');
foreach ($result as $title) {
echo $title->attributes()->address . "<br>";
}
?>
</div>
</body></html>
And index.php
<html>
<head>
<meta name="robots" content="noindex" />
<title>Import Gmail or Google contacts using Google Contacts Data API 3.0 and OAuth 2.0</title>
<style type="text/css">
a:link {color:Chocolate;text-decoration: none;}
a:hover {color:CornflowerBlue;}
.logo{width:100%;height:110px;border:2px solid black;background-color:#666666;}
</style>
</head>
<body>
<div class="logo" >
</div>
<br/>
<div><b>Visit Tutorial: </b><a style="font-size:17px;" href="http://test.multicon.in/test9/" >Import Gmail or Google contacts using Google Contacts Data API 3.0 and OAuth 2.0 in PHP</a></div>
<br/><br/>
<div align="center" >
<a style="font-size:25px;font-weight:bold;" href="https://accounts.google.com/o/oauth2/auth?client_id=1041526369396-kmnbhsos616eqcqimjrs07icn2c176ln.apps.googleusercontent.com&redirect_uri=https://www.test.multicon.in/test9/oauth.php&scope=https://www.google.com/m8/feeds/&response_type=code">Click here to Import Gmail Contacts</a>
</div>
</body>
</html>
Now while clicking on the links in index.php it shows me that the My Project wants to access my Gmail contact...but when it takes me to the redirected page...it shows page not available whereas that page is there. I don't know whether am clear to you or not...if possible please check the link http://test.multicon.in/test9/index.php may be this will help you to understand my problem
finally...I have resolved this issue, the my domain was not added with WWW records, that's why I was getting the error "DNS_PROBE_FINISHED_NXDOMAIN", the moment I have added the WWW records for test.multicon.in,the error resolved

Resources