Jump to content

Google Data Api


JohnOP

Recommended Posts

Hi all i was wondering if someone with exp in youtube api could help me out with this

 

I have a website where i want to let people subscribe to others and first off i auth the user

 

session_start();
set_include_path('path');
require_once 'Zend/Loader.php'; // the Zend dir must be in your include_path
Zend_Loader::loadClass('Zend_Gdata_YouTube');
$yt = new Zend_Gdata_YouTube();

Zend_Loader::loadClass('Zend_Gdata_AuthSub');

function getAuthSubRequestUrl()
{
    $next = 'my site';
    $scope = 'http://gdata.youtube.com';
    $secure = false;
    $session = true;
    return Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session);
}

function getAuthSubHttpClient()
{
    if (!isset($_SESSION['sessionToken']) && !isset($_GET['token']) ){
        echo '<a href="' . getAuthSubRequestUrl() . '">Login!</a>';
        return;
    } else if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) {
      $_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
    }
$httpClient = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']);
    return $httpClient;
}

 

And that takes me to the page to auth my account, then when i go back to my website

and hit the sub button that i made

 

<?php
$username = $_SESSION['username'];
include("connect.php");
$mysql = mysql_query("SELECT * FROM users WHERE username = '$username'");
while($row = mysql_fetch_assoc($mysql)){
?>
<table>
<tr><td>
<?php echo $row['channel']; ?>
</td></tr>
<tr><td>
<form action="sub4sub.php?id=<?php echo $row['id']; ?>" method="POST">
<input type="submit" name="i" value="Sub">
</form>
</td></tr></table>
<?php
}
if (isset($_POST['i'])){
$id = $_GET['id'];
$sql = mysql_query("SELECT * FROM users WHERE id= $id");
$row = mysql_fetch_assoc($sql);
$ytkb = $row['channel'];
// this example assumes that $yt is a fully authenticated service object
getAuthSubHttpClient();
$subscriptionsFeedUrl = "http://gdata.youtube.com/feeds/api/users/default/subscriptions";
$newSubscription = $yt->newSubscriptionEntry();

$channel = $ytkb;
$newSubscription->setUsername(new Zend_Gdata_YouTube_Extension_Username($channel));

// post
$yt->insertEntry($newSubscription, $subscriptionsFeedUrl);
}

?>

 

So should be subscribing to the persons channel that is displayed in the table, but i get this errors

 

Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Expected response code 200, got 401 <HTML> <HEAD> <TITLE>User authentication required.</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF" TEXT="#000000"> <H1>User authentication required.</H1> <H2>Error 401</H2> </BODY> </HTML> ' in /home/u292976682/public_html/Zend/library/Zend/Gdata/App.php:709 Stack trace: #0 /home/u292976682/public_html/Zend/library/Zend/Gdata.php(221): Zend_Gdata_App->performHttpRequest('POST', 'http://gdata.yo...', Array, '<atom:entry xml...', 'application/ato...', NULL) #1 /home/u292976682/public_html/Zend/library/Zend/Gdata/App.php(900): Zend_Gdata->performHttpRequest('POST', 'http://gdata.yo...', Array, '<atom:entry xml...', 'application/ato...') #2 /home/u292976682/public_html/Zend/library/Zend/Gdata/App.php(975): Zend_Gdata_App->post(Object(Zend_Gdata_YouTube_SubscriptionEntry), 'http://gdata.yo...', NULL, NULL, Array) #3 /home/u292976682/public_html/sub4sub.php(123): Zend_Gdata_App->insertEntry(Object(Zend_Gdata_YouTube_Subscrip in /home/u292976682/public_html/Zend/library/Zend/Gdata/App.php on line 709

 

Any help would be great thanks

Link to comment
https://forums.phpfreaks.com/topic/237805-google-data-api/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.