Youtube api (c#) strange error

2019-08-28 06:26发布

问题:

I have been puzzling with this problem for 3 days now but i cant figure out any solution. Excuse me if this is no the place to ask that kind of question. But believe me i have not other alternatives.

I have an application where the user can upload the video and then via youtube api uploads them to a certain youtube channel. This app is hosted in an amazon host. Great so far!

Due to ssl reasons i have to deploy this app in a different host. So i make an exact instance of my host. But the problem is that i get this error when i try to upload via youtube api :

The remote server returned an error: (403) Forbidden.

All my deploy files are copy-paste from one host to another. The structure and configuration of the host is the exact same (as i mentioned before it is an exact instance).

I would be grateful if some of you had any ideas. Again sorry if this is the wrong place to post this question.

Thanks

UPDATE

I updated the youtube dll's with the current version and i have this message:

Invalid Credentials

The weird thing is that i get this message only in a specific youtube/google account. In every other account i try the video gets uploaded correctly.

Maybe is something wrong with the account?

回答1:

"The HTTP body of the 403 Forbidden response should contain an XML description of the error along with it's specific cause."

Assuming you are using HttpWebRequest. Use the WebException.Response to get the body and log the xml response.

try
{
    var http = (HttpWebRequest)WebRequest.Create("youtube api");
    using (var resp = http.GetResponse())
    {
        //Handle api response
    }
}
catch (WebException we)
{
    if (we.Response == null)
        throw; //Rethrow because it doesn't have a body.

    var resp = (HttpWebResponse)we.Response;
    if (resp.StatusCode != HttpStatusCode.Forbidden)
        throw; //We are only handling forbidden, rethrow other statuses.

    using (var sr = new StreamReader(resp.GetResponseStream()))
    {
        var xml = sr.ReadToEnd();
        //Log xml here
    } 
}


回答2:

Ok i figured what the problem was about.

I tried to manually login to youtube from the amazon server and to my suprise it requested a captcha input.

After entering the captcha, everything worked great!