Jump to content

[SOLVED] Sending headers to AuthSub on Youtube API


longtone

Recommended Posts

I'm still stuck on this one problem:

 

All I want to do is get the Youtube username of a visitor.

 

I can get a single use token using this form:

 

 

<form action="https://www.google.com/accounts/AuthSubRequest?next=http%3A%2F%2Fwww.djtutor.com%2Ftest4.php&scope=http%3A%2F%2Fgdata.youtube.com&session=1&secure=0" method="post">

<input type="submit" name="submit value="submit">
</form>

 

And I think I should be able to display a feed of their Youtube profile with this:

 

<?php

$token = (isset( $_GET['token'])) ? $_GET['token'] : false ;

   $ch = curl_init();
   $url = "http://gdata.youtube.com/feeds/api/users/default";
   
   curl_setopt ($ch, CURLOPT_URL, $url);
   curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: AuthSub token="' . $token . '"\nX-GData-Key: key="OUR_DEVELOPER_KEY"\n\r'));
   ob_start();

   curl_exec ($ch);
   curl_close ($ch);
   
   $string = ob_get_contents();

   ob_end_clean();

echo $string;
?>

 

But I get a 401 error, User Authentication required.

 

Is it just a syntax error in the cUrl, or do I need to convert the token to a session token before using it at all? (I'm assuming if it's a single use token I can use it once without converting it)

Any ideas? I'm very new to the notion of sending headers with cUrl

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.