I just implemented Google Api into my app using the YouTube service to get youtube videos. It works as expected as far as getting the results but for some reason MAXRESULTS is not working. It will display results but if i set for example 15 then it shows a endless number of results on the page.
<?php
//Load The Google Api Client
//Added Google Api Support 01/21/2016
set_include_path(get_include_path().PATH_SEPARATOR.'vendor/google/apiclient/src');
//=================================================================================
//START GOOGLE API INTEGRATION
//=================================================================================
$htmlBody = <<<END
<form method="GET">
<div>
Search For YouTube Video<br>
<input type="search" id="q" name="q" placeholder="SEARCH" size="30">
</div>
<input type="submit" value="Search">
</form>
END;
if ( $_GET['q'] )
{
require_once 'Google/Client.php';
require_once 'Google/Service/YouTube.php';
$DEVELOPER_KEY = 'REMOVED FOR OBVIOUS REASONS';
$client = new Google_Client();
$client->setDeveloperKey($DEVELOPER_KEY);
// Define an object that will be used to make all API requests.
$youtube = new Google_Service_YouTube($client);
try {
// Call the search.list method to retrieve results matching the specified
// query term.
$searchResponse = $youtube->search->listSearch('id,snippet', array(
'q' => $_GET['q'],
'maxResults' => 15,
'type' => 'video',
));
$videos = '';
// Add each result to the appropriate list, and then display the lists of
// matching videos.
$i = 0;
foreach ($searchResponse['items'] as $searchResult)
{
switch ($searchResult['id']['kind'])
{
case 'youtube#video':
$videotitle = $searchResult['snippet']['title'];
$videoid = $searchResult['id']['videoId'];
$videoembed = '<iframe width="150" height="150" src="http://www.youtube.com/embed/'.$videoid.'?autoplay=0&hd=1&vq=hd720" frameborder="0" allowfullscreen></iframe>';
$htmloutput .= '
<table width="50%" align="center">
<tr>
<th colspan="2">'.$i.'. '.$videotitle.'</th>
</tr>
<tr>
<td width="40%">'.$videoembed.'</td>
<td width="60%" align="center">
<form action="index.php" method="post" id="conversionForm">
<input type="hidden" name="youtubeURL" value="'.$videoid.'">
<input type="hidden" value="320" name="quality">
<input type="submit" name="submit" value="Create MP3 File">
</form>
</td>
</tr>
</table>
';
$videos .= '<li>'.$htmloutput.'</li>';
break;
}
$i++;
}
$htmlBody .= <<<END
<h3>Videos</h3>
<ul>$videos</ul>
END;
} 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()));
}
}
//=================================================================================
//END GOOGLE API INTEGRATION
//=================================================================================
?>
Wow i must be tired. I figured it out.
Changed
$htmloutput .= '
To
$htmloutput = '
That fixed the problem i was having.
Thank You Guys!
Related
So i was working on a php web application. Here is the form(trackit.php) i am working on.
<?php
function curlPOST($fields) {
$url = 'http://example.com/mailit4.php';
//url-ify the data for the POST^M
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
return $result;
}
$lid = $_GET["lid"];
$list_id = $_GET["list_id"];
$phone=$_GET["phone"];
/*
$filename = 'leadids.txt';
$contents = file($filename);
$myfile = fopen("leadids.txt", "a") or die("Unable to open file!");
*/
$fields = array('lid' => $lid, 'list_id' => $list_id, 'phone'=> $phone);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Client Appreciation Weekend 2016</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<table width="986" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><img src="images/example" alt="example.com" width="600" height="133" style="margin-left:180px;" border="0" usemap="#Map" /></td>
</tr>
</table>
<table width="986" border="0" align="center" cellpadding="0" cellspacing="0">
<form action="<?curlPOST($fields)?>" method="post" >
<tr>
<td>
<label>Phonenumber:</label>
</td>
<input type="hidden" name="lid" id="lid" size="40" value= "<?=$lid?>">
<input type="hidden" name="list_id" id="list_id" size="40" value= "<?=$list_id?>">
<td >
<input type="text" name="phonenumber" id="phonenumber" size="40" value= "<?=$phone?>"> <br>
</td>
</tr>
<tr align="center">
<td>
<input type="submit" name="btnSubmit" value="Submit Data">
</td>
</tr>
</form>
</table>
</body>
</html>
?>
I am posting these three values to mailit4.php using curl post. When i click submit it calls that function and run mailit4.php script which is on the other server. Everything is working fine but when i am trying to redirect my page to thanks.html which is on this server(where trackit.php is). Its doing nothing. Can anyone please how i can redirect to thanks.html
here is my code for mailit4.php
<?php
$db = mysqli_connect('localhost', 'example', 'example', 'example');
$lid = $_POST['lid'];
$list_id = $_POST['list_id'];
$phone=$_POST['phone'];
$sql = "SELECT list_id FROM exampleWHERE lead_id=$lid";
$result = mysqli_query($db,$sql);
$value = mysqli_fetch_row($result);
if ($value[0] != $list_id){
$body = "Leadid " . $lid . " : " . $list_id . "\n\n";
$subject = "Zombie Drip:" . $lid . " : " . $list_id;
mail("example#gmail.com", $subject, $body);
}
$query = mysqli_query($db, "UPDATE example SET list_id=$list_id,called_since_last_reset='N',phone_number=$phone WHERE lead_id=$lid");
if($query){
header('Location: http://example.com/thanks.html/');
exit;
}
else{
$body = "Leadid " . $lid . " : " . $list_id . "\n\n";
$subject = "It could not update the example due to some reasons " .$query ;
mail("example#gmail.com", $subject, $body);
}
?>
Thanks
This code is not working perfectly as <form action="<?curlPOST($fields)?>" method="post" > is wrong.
you are not echoing curlPOST($fields) so the when you are loading this page, your mailit4.php is loading one time and the action of this form are set to self like <form action="" method="post" > and you are thinking your code is working as each time you submit it calles this page as well as mailit4.php. your correct action will be <form action="" method="post" > and put this code after calling function curlPOST
if(!empty($_POST)) curlPOST($fields);
another problem in your code is,
$lid = $_GET["lid"];
$list_id = $_GET["list_id"];
$phone=$_GET["phone"];
method of your form is post and you are trying to catch this data by get
in your mailit4.php you are using mail means you are sending data to somewhere that means, data flushed already, and then you are calling header. instate use file_get_contents() to get contents of thanks.html as this script will not out anything to your browser.
Please return something from your mailit4.php like
If(mail($subject....))
{
echo "ok";
}
And in your curl function
If( $result == "ok" )
{
// redirect to thank you page
}
I am giving idea with little description because i am typing from my mobile
Hope it will help you
Thanks
I have been trying to make Twitter reply code using PHP and it didn't work. When I run it it just post it as a tweet without the reply to the tweet id.
in_reply_to_status_id doesn't work when I run the code.
is there any solution?
<form action="<?php echo $PHP_SELF;?>" method="post">
<input type="submit" name="do"value="do"></input>
<input type="text" name="tweetid" placeholder="tweet id"></input>
<input type="text" name="message" placeholder="message"></input>
</form>
<?php
require_once('twitteroauth.php');
$connect=mysql_connect ("localhost","___","___");
mysql_select_db ("___");
if(isset($connect)){
$do=$_POST ['do'];
$message=$_POST ['message'];
$tweetid=$_POST ['tweetid'];
$consumerKey = '___';
$consumerSecret = '___';
$accessToken= '___';
$accessTokenSecret= '___';
if(isset($do)){
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $accessToken,$accessTokenSecret);
$tt=$tweet->post('statuses/update', array ('status'=>$message , 'in_reply_to_status_id' =>$tweetid));
}}
else {
print "error";
}
mysql_close ();
?>
I want to create php page for upload file into my dropbox.
I have got key and secret key from my dropbox account.
From here I got coding for dropbox but I did not get user id.
How can I get user id of dropbox.
https://www.dropbox.com/developers/core/start/php
list($accessToken, $dropboxUserId) = $webAuth->finish($authCode);
print "Access Token: " . $accessToken . "\n";
I assume you're using the standard PHP Dropbox SDK
$client = new Dropbox\Client($accessToken);
$info = $client->getAccountInfo();
echo $info["uid"];
<?php
error_reporting(E_ALL);
require_once("DropboxClient.php");
// you have to create an app at https://www.dropbox.com/developers/apps and enter details below:
$dropbox = new DropboxClient(array(
'app_key' => "",
'app_secret' => "",
'app_full_access' => true,
),'en');
handle_dropbox_auth($dropbox); // see below
// if there is no upload, show the form
if(empty($_FILES['the_upload'])) {
?>
<form enctype="multipart/form-data" method="POST" action="">
<p>
<label for="file">Upload File</label>
<input type="file" name="the_upload" />
</p>
<p><input type="submit" name="submit-btn" value="Upload!"></p>
</form>
<?php } else {
$upload_name = $_FILES["the_upload"]["name"];
echo "<pre>";
echo "\r\n\r\n<b>Uploading $upload_name:</b>\r\n";
$meta = $dropbox->UploadFile($_FILES["the_upload"]["tmp_name"], $upload_name);
print_r($meta);
echo "\r\n done!";
echo "</pre>";
}
to run before you have to authorized in dropbox apps
I'm attempting to upload a video to YouTube via the API using Zend_Gdata (Zend Framework 1.12.0). I had no problems getting direct upload to work, but browser-based upload always gives me a 400 - INVALID TOKEN error. I'm pretty sure I must be missing something vital but small enough to not notice it.
There are two files involved in this:
index.php
<?php
$youTubeAPIKey = '<API_Key>';
$username = '<user>';
$password = '<pass>';
set_include_path(get_include_path().PATH_SEPARATOR.__DIR__."/vendor");
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
try
{
$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username,
$password,
$service = 'youtube',
$client = null,
$source = 'BrowserUploaderTest', // a short string identifying your application
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
$yt = new Zend_Gdata_YouTube($httpClient, "browser upload test", "Test version 0.1", $youTubeAPIKey);
$videoEntry = new Zend_Gdata_YouTube_VideoEntry();
$videoEntry->setVideoTitle("Test movie");
$videoEntry->setVideoDescription("This is a test movie");
$videoEntry->setVideoPrivate();
// #todo This must be a valid YouTube category, how to get a list of valid categories?
$videoEntry->setVideoCategory('Autos');
$videoEntry->setVideoTags('cars, funny');
// Get an upload token
$tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken';
$tokenArray = $yt->getFormUploadToken($videoEntry, $tokenHandlerUrl);
$token = $tokenArray['token'];
$url = $tokenArray['url'];
// print "Token value: {$tokenArray['token']}\n url: {$tokenArray['url']}\n";
$nextUrl = "http://" . $_SERVER['HTTP_HOST'] . "/uploadDone.php";
}
catch (Zend_Gdata_App_HttpException $httpException)
{
echo $httpException->getRawResponseBody();
}
catch (Zend_Gdata_App_Exception $e) {
echo $e->getMessage();
}
catch (Exception $e)
{
print $e->getTraceAsString();
}
?><!DOCTYPE html>
<html>
<head>
<title>Testing Youtube upload</title>
</head>
<body>
<table>
<tr>
<td>
Url:
</td>
<td>
<?= $url ?>
</td>
</tr>
<tr>
<td>
Token:
</td>
<td>
<?= $token ?>
</td>
</tr>
</table>
<form action="<?= $url ?>.?nexturl=<?= urlencode($nextUrl) ?>" enctype="multipart/form-data" method="post">
<input name="token" type="hidden" value="<?= $token ?>" />
<input name="file" type="file" />
<input type="submit" value="Upload file" />
</form>
</body>
</html>
and uploadDone.php
<?php
print nl2br(print_r($_GET, true));
print nl2br(print_r($_POST, true));
I've searched both on Stack Overflow and spent a couple of hours searching on Google but not found anything that solves it which leads me to believe I'm missing something dead simple. Any help would be appreciated.
A note:
This code is only to test the API usage and is taken mostly from Google's Developer's guide (https://developers.google.com/youtube/2.0/developers_guide_php#Browser_based_Upload) and with a little help from the Yii framework documentation (http://www.yiiframework.com/wiki/375/youtube-api-v2-0-browser-based-uploading/). The production code will be rewritten in a more structured manner but that's not important at the moment.
Your action="<?= $url ?>.?nexturl=<?= urlencode($nextUrl) ?>" looks suspicious; is that an errant . character in there right after your $url variable gets evaluated, messing up the URL?
I am trying to call a publicly available web service from a PHP web page.
The web service is: http://www.webservicex.net/uszip.asmx?WSDL
My code:
<html>
<body>
<?php
$zip = $_REQUEST['zip'];
echo 'zip is'.$zip;
?>
<form action="wszip.php" method="post">
<table cellspacing="10" bgcolor="CadetBlue">
<tr>
<td><B>Enter Zip Code : </B><input type="text" name="zip" /></td>
<td></td>
<td><input type="Submit" value="Find It!"/></td>
</tr>
</table>
<BR><BR><BR><BR>
</form>
<?php
if($zip != "")
{
$wsdl = "http://www.webservicex.net/uszip.asmx?WSDL";
$client = new soapclient($wsdl, true);
$response = $client->GetInfoByZIP($zip);
}
?>
</body>
</html>
You're feeding the ZIP code in incorrectly, and your constructor syntax is also incorrect. Use this syntax instead:
$wsdl = "http://www.webservicex.net/uszip.asmx?WSDL";
$client = new soapclient($wsdl);
$response = $client->GetInfoByZIP(array('USZip' => $zip));
I just tested it, and it works fine. The documentation is here.