Exemple #1
0
 /**
  *
  * @return string
  */
 public function get_user_name()
 {
     return $this->_api->getUserProfile('default')->getUsername();
 }
/**
 * Add a username to the DB using their single-use AuthSub token.
 *
 * @param string $token The single-use AuthSub token of the user to be added.
 * @return void
 */
function addUsername($token)
{
    $httpClient = Zend_Gdata_AuthSub::getHttpClient($token);
    $yt = new Zend_Gdata_YouTube($httpClient, 'YT-UeberActivityViewer', $GLOBALS['ueber-activity-viewer-php_config']['client_id'], $GLOBALS['ueber-activity-viewer-php_config']['dev_key']);
    $yt->setMajorProtocolVersion(2);
    try {
        $userProfile = $yt->getUserProfile('default');
    } catch (Zend_Gdata_Exception $e) {
        error_log("Error getting userProfile: " . $e->getMessage());
        return null;
    }
    unset($yt);
    if (!$userProfile) {
        error_log("UserProfile is null.");
        return null;
    }
    $username = $userProfile->getUsername();
    $userhash = null;
    // get hash
    if ($username) {
        $yt = getYouTubeService();
        try {
            $activitiesFeed = $yt->getFeed('http://gdata.youtube.com/feeds/api/users/' . $username . '/events');
        } catch (Exception $e) {
            echo "Error retrieving user events feed for {$username} | " . $e->getMessage();
            print_r($yt);
        }
        $updatesLink = $activitiesFeed->getLink('updates');
        $hashHref = $updatesLink->getHref();
        $userhash = substr($hashHref, strpos($hashHref, '#') + 1);
        unset($yt);
    } else {
        echo "Could not get user profile for token {$token}.";
        error_log("Could not get user profile for token {$token}.");
        header('Location: ' . "http://{$_SERVER['SERVER_NAME']}{$_SERVER['PHP_SELF']}");
    }
    $mysqli = new mysqli($GLOBALS['ueber-activity-viewer-php_config']['mysql_hostname'], $GLOBALS['ueber-activity-viewer-php_config']['mysql_username'], $GLOBALS['ueber-activity-viewer-php_config']['mysql_password'], $GLOBALS['ueber-activity-viewer-php_config']['mysql_database'], $GLOBALS['ueber-activity-viewer-php_config']['mysql_port'], $GLOBALS['ueber-activity-viewer-php_config']['mysql_socket']);
    if (mysqli_connect_errno()) {
        error_log("Connect failed: " . mysqli_connect_error());
        return null;
    }
    $username = $mysqli->real_escape_string($username);
    $userhash = $mysqli->real_escape_string($userhash);
    $statement = $mysqli->prepare("INSERT IGNORE INTO user (username, hash) VALUES (?,?)");
    $statement->bind_param('ss', $username, $userhash);
    $statement->execute();
    $statement->close();
    $mysqli->close();
    header('Location: ' . "http://{$_SERVER['SERVER_NAME']}{$_SERVER['PHP_SELF']}");
}
                    $youtube = new Zend_Gdata_YouTube($httpClient, APPLICATION_ID, CLIENT_ID, DEVELOPER_KEY);

                    // Variabel $profile akan menyimpan semua informasi profile dari user yang terhubung
                    // dalam bentuk object class Zend_Gdata_YouTube_UserProfileEntry
                    $profile = $youtube->getUserProfile();
                </pre>

                Hasil yang didapat :

                <pre>
<?php 
    $httpClient = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']);
    $httpClient->setHeaders('GData-Version', '2.0');
    $youtube = new Zend_Gdata_YouTube($httpClient, APP_ID, CLIENT_ID, DEV_KEY);
    // Variabel $profile akan menyimpan semua informasi profile dari user yang terhubung
    $profile = $youtube->getUserProfile('default');
    echo '// $profile->getUsername();<br/>';
    echo $profile->getUsername();
    echo '<br/><br/>';
    echo '// $profile->getFirstName();<br/>';
    echo $profile->getFirstName();
    echo '<br/><br/>';
    echo '// $profile->getLastName();<br/>';
    echo $profile->getLastName();
    ?>
                </pre>
            </p>
        <?php 
}
?>
    </div>
Exemple #4
0
 /**
  * displayYouTubeUploadPage
  * 
  * @return void
  */
 function displayYouTubeUploadPage()
 {
     $this->displayHeader();
     $this->checkUserAuthedYouTube();
     $youtubeConfig = getYouTubeConfigData();
     $httpClient = getYouTubeAuthSubHttpClient($youtubeConfig['youtube_key']);
     if ($httpClient === false) {
         // Error message was already displayed by getYouTubeAuthSubHttpClient()
         $this->displayFooter();
         die;
     }
     $youTubeService = new Zend_Gdata_YouTube($httpClient);
     $feed = $youTubeService->getUserProfile('default');
     if (!$feed instanceof Zend_Gdata_YouTube_UserProfileEntry) {
         print '
         <div class="error-alert">' . T_('Could not get YouTube data for user.') . '</div>';
         return;
     }
     $username = $feed->getUsername();
     echo '
     <form action="video.php?upload=youtube" method="post">
         <fieldset>
             <legend><span>' . T_('Upload YouTube Video') . '</span></legend>
             <div class="field-row">
                 <div class="field-label"><label><b>' . T_('YouTube Account') . '</b></label></div>
                 <div class="field-widget">' . $username . '
                 </div>
             </div>
             <div class="field-row">
                 <div class="field-label"><label><b>' . T_('Title') . '</b></label></div>
                 <div class="field-widget">
                     <input type="text" name="title" size="50"/>
                 </div>
             </div>
             <div class="field-row">
                 <div class="field-label"><label><b>' . T_('Description') . '</b></label></div>
                 <div class="field-widget">
                     <textarea cols="50" name="description"></textarea>
                 </div>
             </div>
             <div class="field-row">
                 <div class="field-label"><label><b>' . T_('Category') . '</b></label></div>
                 <div class="field-widget">
                     <select name="category">
                         <option value="Autos">' . T_('Autos &amp; Vehicles') . '</option>
                         <option value="Music">' . T_('Music') . '</option>
                         <option value="Animals">' . T_('Pets &amp; Animals') . '</option>
                         <option value="Sports">' . T_('Sports') . '</option>
                         <option value="Travel">' . T_('Travel &amp; Events') . '</option>
                         <option value="Games">' . T_('Gadgets &amp; Games') . '</option>
                         <option value="Comedy">' . T_('Comedy') . '</option>
                         <option value="People">' . T_('People &amp; Blogs') . '</option>
                         <option value="News">' . T_('News &amp; Politics') . '</option>
                         <option value="Entertainment">' . T_('Entertainment') . '</option>
                         <option value="Education">' . T_('Education') . '</option>
                         <option value="Howto">' . T_('Howto &amp; Style') . '</option>
                         <option value="Nonprofit">' . T_('Nonprofit &amp; Activism') . '</option>
                         <option value="Tech">' . T_('Science &amp; Technology') . '</option>
                     </select>
                 </div>
             </div>
             <div class="field-row">
                 <div class="field-label"><label for="unlisted"><b>' . T_('Unlisted') . '</b></label></div>
                 <div class="field-widget">
                     <input type="checkbox" name="unlisted" id="unlisted_" value="yes" checked="checked"><br/>
                     <small>' . T_('"Unlisted" means that only people who know the link to the video can view it. The video will not appear in any of YouTube\'s public spaces, such as search results, your channel, or the Browse page, but the link can be shared with anyone.') . '</small>
                 </div>
             </div>
             <input class="sub1" type="submit" id="upload_data" name="upload_data" value="' . T_('Next') . '"/>
              &nbsp;' . T_('or') . ' &nbsp;
             <a href="video.php">' . T_('Cancel') . '</a>
         </fieldset>
     </form>';
     $this->displayFooter();
 }
 /**
  * Retrieves a user's profile as an entry
  *
  * @param string $user The username of interest
  * @return Zend_Gdata_YouTube_UserProfileEntry The user profile entry
  */
 public function getAccountInfo($username)
 {
     return $this->yt->getUserProfile($username);
 }
Exemple #6
0
 /**
  * displayEditYouTube 
  * 
  * @return void
  */
 function displayEditYouTube()
 {
     $this->displayHeader();
     $config = getYouTubeConfigData();
     $user = getYouTubeUserData($this->fcmsUser->id);
     // Setup url for callbacks
     $callbackUrl = getDomainAndDir();
     $callbackUrl .= 'settings.php?view=youtube';
     if (!empty($config['youtube_key'])) {
         if (!empty($user['youtube_session_token'])) {
             $httpClient = getYouTubeAuthSubHttpClient($config['youtube_key'], $user['youtube_session_token']);
             $youTubeService = new Zend_Gdata_YouTube($httpClient);
             $feed = $youTubeService->getUserProfile('default');
             if (!$feed instanceof Zend_Gdata_YouTube_UserProfileEntry) {
                 print '
         <div class="error-alert">' . T_('Could not get YouTube data for user.') . '</div>';
                 return;
             }
             $username = $feed->getUsername();
             $user = '******' . $username . '">' . $username . '</a>';
             $status = sprintf(T_('Currently connected as: %s'), $user);
             $link = '<a class="disconnect" href="?revoke=youtube">' . T_('Disconnect') . '</a>';
         } else {
             $url = Zend_Gdata_AuthSub::getAuthSubTokenUri($callbackUrl, 'http://gdata.youtube.com', false, true);
             $status = T_('Not Connected');
             $link = '<a href="' . $url . '">' . T_('Connect') . '</a>';
         }
     }
     echo '
     <div class="social-media-connect">
         <img class="icon" src="ui/img/youtube.png" alt="YouTube"/>
         <h2>YouTube</h2>
         <p>' . T_('YouTube allows users to discover, watch and share videos.') . '</p>
         <div class="status">' . $status . '</div>
         <div class="action">' . $link . '</div>
     </div>';
     $this->displayFooter();
 }