You can use the below function for any http request. This will give response and error message too.
Main Topics
Browse All TopicsHello,
What I am trying to do is use YouTube API in order to gather some susbscription information (see http://code.google.com/api
So what I do is:
string url = "http://gdata.youtube.com/
WebRequest request;
try
{
Application.DoEvents();
request = WebRequest.Create(url);
string usernamePassword = TUsername + ":" + TPassword;
CredentialCache mycache = new CredentialCache();
mycache.Add(new Uri(url), "Basic", new NetworkCredential(TUsernam
request.Credentials = mycache;
request.Headers.Add("Autho
WebResponse response = request.GetResponse();
Stream receiveStream = response.GetResponseStream
StreamReader reader = new StreamReader(receiveStream
content = reader.ReadToEnd();
But it returns me 401 unauthorized error...
Im new to YouTube API, so please help me what I am doing wrong...!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I am using API, I have Developer key, username and password. See here:
YouTubeRequestSettings settings = new YouTubeRequestSettings("Hi
YouTubeRequest request = new YouTubeRequest(settings);
string feedUrl = "http://gdata.youtube.com/
YouTubeQuery query = new YouTubeQuery(feedUrl);
SubscriptionFeed subFeed = service.GetSubscriptions(q
foreach (SubscriptionEntry entry in subFeed.Entries)
{
MessageBox.Show(entry.Titl
}
default in url means I am logged in so it auto goes to my username.
This is what google has to say regarding your error. It seems either your token is invalid, or expired.
Authentication errors
An authentication error, which is identified by a <domain> tag value of yt:authentication, identifies a problem related to an improperly authenticated request to execute an API function requiring user authentication. Authentication errors could be identified with HTTP 401 or 403 response codes.
Authentication errors may include a <location> element. If so, the element's value will identify the header that caused the authentication error.
For authentication errors, the <code> tag will contain one of the following values:
InvalidToken - This code indicates that the authentication token specified in the Authorization header is invalid.
<?xml version='1.0' encoding='UTF-8'?>
<errors>
<error>
<domain>yt:authentication</do
<code>InvalidToken</code>
<location type='header'>Authorization
</error>
</errors>
TokenExpired - This code indicates that the authentication token specified in the Authorization header has expired.
<?xml version='1.0' encoding='UTF-8'?>
<errors>
<error>
<domain>yt:authentication</do
<code>TokenExpired</code>
<location type='header'>Authorization
</error>
</errors>
Business Accounts
Answer for Membership
by: GVNPublic123Posted on 2009-11-07 at 05:09:07ID: 25766178
I also tried using the API library:
den for privacy, TUsername, TPassword);
feeds/api/ users/defa ult/ subscr iptions"; uery);
YouTubeRequestSettings settings = new YouTubeRequestSettings(hid
YouTubeRequest request = new YouTubeRequest(settings);
string feedUrl = "http://gdata.youtube.com/
YouTubeQuery query = new YouTubeQuery(feedUrl);
SubscriptionFeed subFeed = service.GetSubscriptions(q
foreach (SubscriptionEntry entry in subFeed.Entries)
{
//do something
}
And it gives me exception on 401 - Unauthorized!!! Im angry now!
I tried with YouTube account (TUsername, TPass) and Google Account linked to my YouTube account, and it fails in both ways!