Jump to content

Lone_Ranger

Members
  • Posts

    65
  • Joined

  • Last visited

Everything posted by Lone_Ranger

  1. Solved it done, dusted all upgraded from API 2 to API 3
  2. require_once ($_SERVER["DOCUMENT_ROOT"].'/google-api-php-client/src/Google_Client.php'); require_once ($_SERVER["DOCUMENT_ROOT"].'/google-api-php-client/src/contrib/Google_YouTubeService.php'); $DEVELOPER_KEY = 'xxx-xxx-xxx'; $client = new Google_Client(); $client->setDeveloperKey($DEVELOPER_KEY); $youtube = new Google_YoutubeService($client); $channel = sentuamsg; try { $channelsResponse = $youtube->channels->listChannels('contentDetails', array( $channel => 'true', )); $htmlBody = ''; foreach ($channelsResponse['items'] as $channel) { $uploadsListId = $channel['contentDetails']['relatedPlaylists']['uploads']; $playlistItemsResponse = $youtube->playlistItems->listPlaylistItems('snippet', array( 'playlistId' => $uploadsListId, 'maxResults' => 13 )); $htmlBody .= "<h3>Videos in list $uploadsListId</h3><ul>"; foreach ($playlistItemsResponse['items'] as $playlistItem) { $htmlBody .= sprintf('<li>%s (%s)</li>', $playlistItem['snippet']['title'], $playlistItem['snippet']['resourceId']['videoId']); } $htmlBody .= '</ul>'; } } catch (Google_ServiceException $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())); } Hi I have been working with API 2 recently but as we all know that is depreciated in April 2015 meaning all my work will be lost if I do not transfer over to API 3 I am trying to work API 3 out. What I am trying to do here is, I am trying to access the user account called SENTUAMSG, access his playlist PLZgnlVMqNnAok3nxF763JFz0WYWA6o783 and grabbed the 13 most recent uploaded videos to that playlist. The information I would want to echo out is - Video ID (id print after watch?v= from the youtube.com navigation) - Thumbnail (the video thumbnail) - Video Description - Video Title Anyone able to help me?
  3. $feedURL = 'http://gdata.youtube.com/feeds/api/users/' . $user . '/uploads?orderby=published&max-results=' . $video_amount; I changed the $feedurl to the above so the latest published video shows but in my list now everything is in ID order, so USER 1 will be top going down to USER 13. I wanted the user with the latest PUBLISHED video to be top with the rest following so it always changes with a new content showing
  4. The only thing I did extra was on the MYSQL query I added ORDER BY RAND() LIMIT 13 preferably I would like it to be ordered by most recent video but I guess that is more related to the Youtube API as nothing database side would do that
  5. <?php //Adding limit to the end would get you a limited amount of results $communityvideos = mysql_query("SELECT * FROM userdb WHERE rights='user' && youtube<>'' LIMIT 13"); //end your while loop and create the $v array $v = array(); //define array while ($youtube = mysql_fetch_assoc($communityvideos)) { $v[] = trim($youtube['youtube']); //is this the user? //check that v array is not empty if (!empty($v)) { //here we get each users count for videos $user_count = array_count_values($v); //Now loop through the 13 results from $user_count array which has usernames and amounts of videos each foreach ($user_count as $user => $video_amount) { //echo "$user has $video_amount <br />"; } $feedURL = 'http://gdata.youtube.com/feeds/api/users/' . $user . '/uploads?max-results=' . $video_amount; $sxml = simplexml_load_file($feedURL); foreach ($sxml->entry as $entry) { $media = $entry->children('media', true); $watch = (string) $media->group->player->attributes()->url; $thumbnail = (string) $media->group->thumbnail[0]->attributes()->url; parse_str(parse_url($watch, PHP_URL_QUERY), $my_array_of_vars); //you can add the rest } } //end $user_count loop } //end if $v ?> I do apologise my good man your first answer worked marvellously I should have never doubted it and tried it first
  6. error_reporting(E_ALL); $feedURL = 'http://gdata.youtube.com/feeds/api/playlists/[theusername]?max-results=13'; $sxml = simplexml_load_file($feedURL); $i=0; foreach ($sxml->entry as $entry) { $media = $entry->children('media', true); $watch = (string)$media->group->player->attributes()->url; $thumbnail = (string)$media->group->thumbnail[0]->attributes()->url; parse_str( parse_url( $watch, PHP_URL_QUERY ), $my_array_of_vars ); //any silky smooth layout someone wanted to add would go in this gap $i++; if($i==5) { $i=0; } } forget the new response then sorry. It was something someone said would work and I could not understand it how it would help me. The original code as seen above was designed just to access the youtube API and retrieve the latest videos for 1 user. This would show those videos for that one user. I was using this concept. The difference I did was create a column in USERDB where a user could type there youtube username into it so we could retrieve there vidoes. This cell was called YOUTUBE. Then I wanted to create a dedicated page where using this concept of retrieving videos off the username, I could have a solo page which would only contain 13 videos in total from all those usernames I had stored in my database off the YOUTUBE column. My database does not contain any links to the videos, does not contain anything else except for the YOUTUBE username.
  7. Sorry, you werent very clear on your answer. First of get the total videos uploaded by calling the api with a json format: http://gdata.youtube.com/feeds/api/users/LinusTechTips/uploads?v=2&alt=jsonc use: $json = json_decode($jsonString); print($json->data->totalItems . "\n"); to get the viewcount, then you can calculate the rest! $totalItems = $json->data->totalItems; $maxResults = 50 $xmlResults = array(); for($i = $maxResults > $totalItems-50; $i+$maxResults) { $xmlResults[] = simplexml_load_file( 'http://gdata.youtube.com/feeds/api/users/LinusTechTips/uploads?max-results=' . $i ); } To be clear; this is not tested. So im not sure it works; but this is the way to do it. sorry I did find an answer for this but I do not understand the first part, apparently this is the best way to do it. My problem is where he put the username "LINUSTECHLIPS" that is where I need to have my . $USER . as a loop, as the $USER would be going through the list of youtube usernames I have and want to get videos from. Youtube API tends to put videos in most recent uploaded anyway, so from those usernames in my database all I want is 13 videos in total from all the users. That's why I had a $maxresults = 13 except for on my version it did 13 videos from each user not just 13 in total.
  8. correct "youtube" was the user as my database only has the username stored in it
  9. $communityvideos = mysql_query("SELECT * FROM userdb WHERE rights='user' && youtube<>''"); while($youtube = mysql_fetch_assoc($communityvideos)) { I have updated the SQL query to the above, this was done to get rid of some of the duplicate problem where users who contained a blank field under youtube would be showing up in my result.
  10. I have attached the file http://www.sentuamessage.com/index.php?action=communitytube is the example of what is happening Hi, I have a table in my database that has a bunch of usernames stored in a column, I am using that column to retrieve the usernames and access there youtube account to retrieve the most recent 13 videos. Any blank left cell should not show anything. Right now the code is retrieving the users videos but is duplicating them. One users videos would show 26 times. The other problem I have is that I do not want to show 13 videos for each user. I wanted to access all the recent videos from every user who input there username in the youtube field but only show 13 recent videos in total from all the users. I have attached the file can anyone help me please? ztest.php
  11. Resolved it my thanks but thank you for everyone for the tips
  12. ok I have a weeks holiday very soon I will look into that but do you think this is related to why when I try to do a post that I get a blank result? See the problem is when I get the blank result and go back to redo the post I get an my selective double post error. Once my timer has expired and I try do the same post again it works fine and I get a success message saying my post went through. I just do not understand why I get a blank result?
  13. if (isset($_POST) && !empty($_POST)) { if (isset($_SESSION['posttimer'])) { if ( (time() - $_SESSION['posttimer']) <= 10) { //less than 10 seconds result } else { //more than 10 seconds result } } $_SESSION['posttimer'] = time(); } To be fair if I break it up simpler the whole way the timer is scripted as follows is that easier to understand?
  14. if (isset($_SESSION['posttimer'])) { if ( (time() - $_SESSION['posttimer']) <= 10) { echo "<p align=center><b>Bit of a problem here, Double Post attempt has been found. Don't worry we stopped it.</b></p>"; echo "<p align=center>If you have not returned to your page <a href=http://www.sentuamessage.com/blog.php?who=$content[id]>Click Here</a>"; echo "<meta http-equiv=refresh content=15;URL=http://www.sentuamessage.com/blog.php?who=$content[id] />"; } else { } } $_SESSION['posttimer'] = time(); } I've had no problems with it, works fine, like I stated the script worked perfectly fine before I added in that in is when I started to occur problems where the blank result would come up when creating a post. Like I said the post would create a blank result the first time but the second time of trying it would respond and add the content into the database or if any error message needed to be displayed like "double post" or "blank field" error those would appear. Any help why I am getting that problem?
  15. if ($action == "discussion") { if ($_POST['comment'] == "") { echo "<p align=center>Sorry your comment was not posted due to the comment being blank. You will be redirected in a few seconds so please try again</p> <p align=center>If you have not returned to your page <a href=http://www.sentuamessage.com/blog.php?who=$content[id]>Click Here</a>"; echo "<meta http-equiv=refresh content=15;URL=http://www.sentuamessage.com/blog.php?who=$content[id] />"; include("bottom.php"); exit; } if (isset($_POST) && !empty($_POST)) { if (isset($_SESSION['posttimer'])) { if ( (time() - $_SESSION['posttimer']) <= 10) { echo "<p align=center><b>Bit of a problem here, Double Post attempt has been found. Don't worry we stopped it.</b></p>"; echo "<p align=center>If you have not returned to your page <a href=http://www.sentuamessage.com/blog.php?who=$content[id]>Click Here</a>"; echo "<meta http-equiv=refresh content=15;URL=http://www.sentuamessage.com/blog.php?who=$content[id] />"; } else { $sumscore = $row[score] + 2; $sumcomments = $row[comments] + 1; $con=mysqli_connect("DETAILS FOR SQL STUFF IN HERE BUT DELETED FOR PURPOSES OF THE FORUM"); if (mysqli_connect_errno()) { echo "<p align=center>Failed to connect to MySQL: </p>" . mysqli_connect_error(); } $sql="INSERT INTO comments (userid, topicid, category, topicname, comment, date, name, address, avatar) VALUES ('$row[id]','$content[id]','blogs','$content[topic]','$_POST[comment]','$today','$row[name]','http://www.sentuamessage.com/blog.php?who=$content[id]', '$row[cavatar]')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } mysql_query("INSERT INTO notifications (userid, username, nuser, message, address, date, time) VALUES ('$row[id]','$row[name]','$content[postedid]','$row[name] has commented on your Blog','http://www.sentuamessage.com/blog.php?who=$who','$today', '$time')") or die(mysql_error()); mysql_query("UPDATE userdb SET comments='$sumcomments', score='$sumscore' WHERE username='$_SESSION[username]'") or die(mysql_error()); echo "<p align=center>Your comment has been submitted. You should be redirected back to your page in a few seconds</p> <p align=center>If you have not returned to your page <a href=http://www.sentuamessage.com/blog.php?who=$content[id]>Click Here</a>"; echo "<meta http-equiv=refresh content=2;URL=http://www.sentuamessage.com/blog.php?who=$content[id] />"; mysqli_close($con); } } $_SESSION['posttimer'] = time(); } include("bottom.php"); exit; } I am rattling my brain here. I had added a code into my script to get rid of double posts, it has a timer which stops people double posting within 10 seconds. Though since inserting the code you have an error where you will have to double post the same post because instead of inserting the post content into the database the submit button comes back with a blank result. Why is this happening? (blank result instead of saying "post successfully posted etc." or "post not posted" it just comes up blank with no entry going into the database. This results in you having to re type your comment and re submit it hoping second time lucky) This is my code once the submit has been hit.
  16. some great advice thank you. I will look into this
  17. // ---------------- SEND MAIL FORM ---------------- $to=$username; $subject="SentUAMessage - Verify Account"; $header= "MIME-Version: 1.0" . "\r\n"; $header .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; $header .='from: SentUAMessage <customerservice@sentuamessage.com>' . "\r\n"; $message="<html><body><div align=center> <table border=1 width=30% cellspacing=0 cellpadding=0 bordercolor=#000000> <tr> <td height=1 valign=top> <table border=0 width=100% cellspacing=0 cellpadding=0> <tr> <td bgcolor=#008000 height=1 valign=top></td> </tr> <tr> <td height=1 valign=top><img src=http://www.sentuamessage.com/emailheader.jpg></img></td> </tr> <tr> <td bgcolor=#008000 height=1 valign=top></td> </tr> </table> </td> </tr> </table> </div> <div align=center> <table border=0 width=51% cellspacing=0 cellpadding=0> <tr> <td> </td> </tr> <tr> <td height=1 valign=top> <table border=1 width=100% cellspacing=0 cellpadding=0 bordercolor=#000000> <tr> <td height=1 valign=top> <table border=0 width=100% cellspacing=0 cellpadding=0> <tr> <td height=1 valign=top><img src=http://www.sentuamessage.com/emailheadertop.jpg></img></td> </tr> <tr> <td height=1 valign=top> <h3 align=center><b>Your Confirmation Link</b></h3> <table border=0 width=100% cellspacing=0 cellpadding=0> <tr> <td width=6 height=1 valign=top> </td> <td height=1 valign=top><p>Click on this link to activate your account:</p>"; $message.="<p align=center><b><a href=http://www.sentuamessage.com/regconfirmation.php?passkey=$confirm_code>Confirm Reigstration</a></b></p>"; $message.="</td> <td width=6 height=1 valign=top> </td> </tr> </table> </td> </tr> </table> </td> </tr> </table> </td> </tr> </table> </div></body></html>"; $sentmail = mail($to,$subject,$message,$header); I made a verification system and the code is meant to be emailed to the user aka $username field where the email of the user is entered. I had tested this and realised on my Hotmail that either the email would arrive delayed, not arrive at all or would come into the Junk mail. How do I make it that it is more consistent and actually arrive to my users?
  18. so if I did $header.="MIME-VERSION: 1.02 $header.="content-type= text/html; charset=UTF-8"; should resolve it
  19. yea only thing im looking at now is how to get the HTML to show as a layout instead of script when the email is sent
  20. the Customerservice email address is a real email address
  21. got it working, basically the second one $message tag I messed up it should have been $message "html"; $message. "html"; $message."html"; not $message "html"; $message."html"; $message "html";
  22. guess I can try more and wait longer to see if it is something that is just delayed.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.