Search code examples
javascriptyoutubeyoutube-apigoogle-oauthgoogle-signin

oAuth Consent Screen Not Displaying


I am trying to get the youtube channel name and the number of subscribers using the below code:

var youtubeAuthResponse = [],youtubeChannelResponse = [];
function authenticate() {
  showNewLoader('show');
  return gapi.auth2.getAuthInstance()
  .signIn({scope: "https://www.googleapis.com/auth/youtube.readonly"})
  .then(function(response) {  
    console.log( response);
    youtubeAuthResponse['token_details'] = response.tc; 
    youtubeAuthResponse['google_email'] = '';
    youtubeAuthResponse['google_id'] = '';
    showNewLoader('hide');
  },
  function(err) { console.error("Error signing in", err); showNewLoader('hide');});
}
function loadClient() {
  showNewLoader('show');
  gapi.client.setApiKey("XXXX");
  return gapi.client.load("https://www.googleapis.com/discovery/v1/apis/youtube/v3/rest")
  .then(function() { execute();},
    function(err) { console.error("Error loading GAPI client for API", err);showNewLoader('hide');});
}
/*Make sure the client is loaded and sign-in is complete before calling this method.*/
function execute() {
  return gapi.client.youtube.channels.list({
    "part": [
    "snippet",
    "statistics"
    ],
    "mine": true
  })
  .then(function(response) {
    /*Handle the results here (response.result has the parsed body).*/
    youtubeChannelResponse = response.result;
    storeYoutubeData();
  },
  function(err) { console.error("Execute error", err); showNewLoader('hide') }).then(function(){
  });
}

gapi.load("client:auth2", function() {
  gapi.auth2.init({client_id: "XXXXXX",
    'access_type':'offline'});
});

After signing in, I get the following error from google:

"The request uses the <code>mine</code> parameter but is not properly authorized."

Also the consent screen is never displayed.

enter image description here

Any help on this is greatly appreciated.

@DaImTo


Solution

  • The reason behind this was that I had already granted permission / consent to the scopes with the email address I have been trying.

    Regardless of how much I tried after clearing cache and with different browsers the consent screen did not appear for that email address.

    Using a new email address (youtube channel) worked for me.