Randika
Randika

Reputation: 753

YoutubeAPI returns 401 Invalid Credentials error when try to upload video to youtube using Youtube Data API(V3)

I am trying to upload video to Youtube using Angular File Uploader,OAuth and Youtube Data API(v3) in Codeigniter project. But It always fails with 401 Invalid Credentials response. I tried creating a youtube channel as suggested by other answer but it didn't work for me.

This is my POST url structure

https://www.googleapis.com/upload/youtube/v3/videos?client_id={clientID}&access_token={accessToken}&part=snippet&mine=true

Please can someone explain me the procedure for do this successfully I am new to this.

Upvotes: 2

Views: 1570

Answers (1)

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 117126

Invalid Credentials means that The access token you're using is either expired or invalid. You should check the full error for more information. It normally looks something like this.

401: Invalid Credentials Invalid authorization header.

{
  "error": {
    "errors": [
      {
        "domain": "global",
        "reason": "authError",
        "message": "Invalid Credentials",
        "locationType": "header",
        "location": "Authorization",
      }
    ],
    "code": 401,
    "message": "Invalid Credentials"
  }
}

Videos: list is a public request this means that technically you only need an API key.

https://www.googleapis.com/upload/youtube/v3/videos?key=yourkey

You can use an access_token which was gained from Oauth2 authencation.

https://www.googleapis.com/upload/youtube/v3/videos?access_token=yourtoken

There is no need to add client_id this may be what is causing your problem.

Upvotes: 2

Related Questions