longtone Posted March 31, 2008 Share Posted March 31, 2008 OK, I'm very new to using headers, so I might be going about this completely wrong: I want to view a user's Youtube profile using the GData API After successfully requesting a token I run this PHP script: <?php if (isset( $_GET['token'])) { $token = $_GET['token']; } //Authorise header('Authorization: AuthSub token="' . $token . '"' ); header('X-GData-Key: key="my_developer_key" '); echo '<p><a href="http://gdata.youtube.com/feeds/api/users/default" >Get Profile</a>'; ?> But I get a 401 error User authentication required. Am I using these headers properly? Link to comment https://forums.phpfreaks.com/topic/98790-solved-gdata-authentication-with-php-headers-am-i-doing-this-right/ Share on other sites More sharing options...
longtone Posted April 1, 2008 Author Share Posted April 1, 2008 changed it to file_get_contents instead of a link: <?php //Get Token if (isset( $_GET['token'])) { $token = $_GET['token']; } //Authorise header('Authorization: AuthSub token="' . $token . '"' ); header('X-GData-Key: key="my_developer_key" '); //Request profile echo file_get_contents("http://gdata.youtube.com/feeds/api/users/default") ; ?> Still get the same error though This is what they're asking for: When you make an authenticated API request using an AuthSub authentication token, your request needs to specify the Authorization HTTP request header as shown in the example below. Note: In this document, sample requests use AuthSub syntax unless otherwise specified. Authorization: AuthSub token=<authentication_token> X-GData-Key: key=<developer_key> Am I doing the right thing with headers at all? Link to comment https://forums.phpfreaks.com/topic/98790-solved-gdata-authentication-with-php-headers-am-i-doing-this-right/#findComment-506570 Share on other sites More sharing options...
discomatt Posted April 1, 2008 Share Posted April 1, 2008 No, you're defining the headers of the page that's executing. You have to make a request for the information with cURL and include those header in that stream. Link to comment https://forums.phpfreaks.com/topic/98790-solved-gdata-authentication-with-php-headers-am-i-doing-this-right/#findComment-506578 Share on other sites More sharing options...
longtone Posted April 2, 2008 Author Share Posted April 2, 2008 Ah yes, that makes sense. I'll go and mug up on cURL, or maybe it's time to get the Zend out. Thanks Link to comment https://forums.phpfreaks.com/topic/98790-solved-gdata-authentication-with-php-headers-am-i-doing-this-right/#findComment-506993 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.