Re: token invalid - Error 401

Showing 1-1 of 1 messages
Re: token invalid - Error 401 Jeffrey Posnick 8/17/12 2:19 PM
Hello Pascal,

 Are you saying that your ClientLogin request succeeds, but then you get a 401 error when you try to make a request using the auth token you get back?

 To take a wild guess as to why that might be, I'd say it's because you're urlencode()ing your auth token. It's not being used in a URL and doesn't need to be escaped.

 You can also just use the PHP client library to make your requests:


Cheers,
-Jeff Posnick, YouTube API Team
YouTube Developer Relations is hiring! developers.google.com/jobs


On Wednesday, August 15, 2012 6:02:35 AM UTC-4, Pascal de Laroche wrote:

Hi i dont understand why i keep getting the token invalid error 401 message  the authentication seems to be valid thanks for your help
 
$ch = curl_init( );  
$key = 'AI39si5rS1HwjlXHUcZCq6hsjCCoKhKhdzSEtxNlj83dKu6tM7rgCrgHnzpxnSrR7bo_X3G1kADkasQZFUprDivtxhQYKUELGQ' ;
$curlheader = Array("Content-Type: application/atom+xml") ;
$curlheader = array ('Content-Type: application/x-www-form-urlencoded')  ;
$usr = urlencode('pasca...@gmail.com');
$pas = 'xxxx' ;
$post = "Email=$usr&Passwd=$pas&service=youtube&source=chasser-local" ;
$url = "https://www.google.com/accounts/ClientLogin" ;
curl_setopt_array($ch, array( 
    CURLOPT_URL => $url , 
    CURLOPT_HTTPHEADER =>  $curlheader,
    CURLOPT_POST => true,
    CURLOPT_SSL_VERIFYPEER => false ,
    CURLOPT_POSTFIELDS => $post , 
    CURLOPT_RETURNTRANSFER => true   ) ) ;
$auth = curl_exec($ch); 
// $html = new SimpleXMLElement ($html) ;
$auth = trim($auth) ;
if ( $auth != "Error=BadAuthentication" ) {
 
    $auth = explode("\n", $auth);
    $auth = explode('=',$auth[3] ); 
    $auth = $auth[2];
    $url = "https://gdata.youtube.com/feeds/api/playlists/A788AA02208A8EDF?v=2" ;
    $curlheader = Array("Content-Type: application/atom+xml") ;
    $curlheader[]= 'Authorization: GoogleLogin auth='. urlencode($auth)  ;
     $curlheader[]= 'X-GData-Key: key='.$key ;
    curl_setopt_array($ch, array( 
        CURLOPT_URL => $url , 
        CURLOPT_HTTPHEADER =>  $curlheader,
        // CURLOPT_POST => true,
        CURLOPT_SSL_VERIFYPEER => false ,
        // CURLOPT_POSTFIELDS => $post , 
        CURLOPT_RETURNTRANSFER => true   ) ) ;
    $xml = curl_exec($ch); 
    print_r($xml);
}
curl_close($ch) ;