Youtube data api asks for consent while accesstype is set to offlineHow do I get a YouTube video thumbnail from the YouTube API?Why do access tokens expire?Youtube API v.3 - PHP - Refresh Token revoked unexpectlyOAuth2.0 token strange behaviour (Invalid Credentials 401)How to set AccessType as offline in Google.Apis.Core 1.9 in C#Google Client: Refreshing RefreshToken gives “invalid_grant” errorGoogle API PHP offline access, “invalid_grant: Code was already redeemed”redirect_uri_mismatch when request an offline token from Google / Youtube OAuth APIPHP Google API Refresh TokenC# set access_type = offline for AuthorizeAsync?

I hit a pipe with a mower and now it won't turn

Understanding Lasso Regression's sparsity geometrically

When are digital copies of Switch games made available to play?

Why are there so many religions and gods?

Why don't all electrons contribute to total orbital angular momentum of an atom?

Procedurally generate regions on island

Can you sign using a digital signature itself?

Reverse of diffraction

I'm reinstalling my Linux desktop, how do I keep SSH logins working?

Mean Value Theorem: Continuous or Defined?

Why do the keys in the circle of fifths have the pattern of accidentals that they do?

In native German words, is Q always followed by U, as in English?

How hard is it to sell a home which is currently mortgaged?

Questions about authorship rank and academic politics

Inquiring about the possibility of a job

Most elegant way to write a one shot IF

How to fix a dry solder pin in BGA package?

Why isn’t the tax system continuous rather than bracketed?

Why was Mal so quick to drop Bester in favour of Kaylee?

Are there any features that help with the roll to avoid the destruction of a Wand of Fireballs when using the last charge?

Does Anosov geodesic flow imply asphericity?

What does grep -v "grep" mean and do?

Was it really unprofessional of me to leave without asking for a raise first?

Different budgets within roommate group



Youtube data api asks for consent while accesstype is set to offline


How do I get a YouTube video thumbnail from the YouTube API?Why do access tokens expire?Youtube API v.3 - PHP - Refresh Token revoked unexpectlyOAuth2.0 token strange behaviour (Invalid Credentials 401)How to set AccessType as offline in Google.Apis.Core 1.9 in C#Google Client: Refreshing RefreshToken gives “invalid_grant” errorGoogle API PHP offline access, “invalid_grant: Code was already redeemed”redirect_uri_mismatch when request an offline token from Google / Youtube OAuth APIPHP Google API Refresh TokenC# set access_type = offline for AuthorizeAsync?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have implemented the Google Youtube data api in a website, to let users see videos of certain channels. I have read the documentation from Google on how to use it, and used the offline accesstype since it lets the API autorize itself, refreshing the access token after it expires.



The API is working, but i still get prompt for autorization after 1 hour (default time for expiration of access token), while having the code that refresh the access token automatically.



I didnt provide all the code im using, only the code that handles the API setup and expiration of tokens, since the other code works fine.



Any help to what im doing wrong here would be greatly appreciated.

Updated



$client = new Google_Client();
$client->setAuthConfigFile($config);
$client->setRedirectUri($redirect);
$client->addScope('https://www.googleapis.com/auth/youtube.readonly');
$client->setAccessType('offline');

if(file_exits($aToken){
$accessToken = file_get_contents($aToken);
$client->setAccessToken($accessToken);

if($client->isAccessTokenExpired())
if($client->getRefreshToken())
$client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
$client->setAccessToken($client->getAccessToken());
file_put_contents($aToken, $client->getAccessToken());
else
authorize();











share|improve this question






























    1















    I have implemented the Google Youtube data api in a website, to let users see videos of certain channels. I have read the documentation from Google on how to use it, and used the offline accesstype since it lets the API autorize itself, refreshing the access token after it expires.



    The API is working, but i still get prompt for autorization after 1 hour (default time for expiration of access token), while having the code that refresh the access token automatically.



    I didnt provide all the code im using, only the code that handles the API setup and expiration of tokens, since the other code works fine.



    Any help to what im doing wrong here would be greatly appreciated.

    Updated



    $client = new Google_Client();
    $client->setAuthConfigFile($config);
    $client->setRedirectUri($redirect);
    $client->addScope('https://www.googleapis.com/auth/youtube.readonly');
    $client->setAccessType('offline');

    if(file_exits($aToken){
    $accessToken = file_get_contents($aToken);
    $client->setAccessToken($accessToken);

    if($client->isAccessTokenExpired())
    if($client->getRefreshToken())
    $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
    $client->setAccessToken($client->getAccessToken());
    file_put_contents($aToken, $client->getAccessToken());
    else
    authorize();











    share|improve this question


























      1












      1








      1








      I have implemented the Google Youtube data api in a website, to let users see videos of certain channels. I have read the documentation from Google on how to use it, and used the offline accesstype since it lets the API autorize itself, refreshing the access token after it expires.



      The API is working, but i still get prompt for autorization after 1 hour (default time for expiration of access token), while having the code that refresh the access token automatically.



      I didnt provide all the code im using, only the code that handles the API setup and expiration of tokens, since the other code works fine.



      Any help to what im doing wrong here would be greatly appreciated.

      Updated



      $client = new Google_Client();
      $client->setAuthConfigFile($config);
      $client->setRedirectUri($redirect);
      $client->addScope('https://www.googleapis.com/auth/youtube.readonly');
      $client->setAccessType('offline');

      if(file_exits($aToken){
      $accessToken = file_get_contents($aToken);
      $client->setAccessToken($accessToken);

      if($client->isAccessTokenExpired())
      if($client->getRefreshToken())
      $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
      $client->setAccessToken($client->getAccessToken());
      file_put_contents($aToken, $client->getAccessToken());
      else
      authorize();











      share|improve this question
















      I have implemented the Google Youtube data api in a website, to let users see videos of certain channels. I have read the documentation from Google on how to use it, and used the offline accesstype since it lets the API autorize itself, refreshing the access token after it expires.



      The API is working, but i still get prompt for autorization after 1 hour (default time for expiration of access token), while having the code that refresh the access token automatically.



      I didnt provide all the code im using, only the code that handles the API setup and expiration of tokens, since the other code works fine.



      Any help to what im doing wrong here would be greatly appreciated.

      Updated



      $client = new Google_Client();
      $client->setAuthConfigFile($config);
      $client->setRedirectUri($redirect);
      $client->addScope('https://www.googleapis.com/auth/youtube.readonly');
      $client->setAccessType('offline');

      if(file_exits($aToken){
      $accessToken = file_get_contents($aToken);
      $client->setAccessToken($accessToken);

      if($client->isAccessTokenExpired())
      if($client->getRefreshToken())
      $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
      $client->setAccessToken($client->getAccessToken());
      file_put_contents($aToken, $client->getAccessToken());
      else
      authorize();








      php google-api google-oauth youtube-data-api google-api-php-client






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 26 at 16:57







      abobakrdy

















      asked Mar 25 at 12:39









      abobakrdyabobakrdy

      457 bronze badges




      457 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          1














          You are applying your refresh token but not actually using it to fetch a new access token.



          $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
          $client->setAccessToken($client->getAccessToken());


          My sample Oauth2Authentication.php






          share|improve this answer























          • Thanks, i also didnt have any refresh token because i didnt set the approvalprompt parameter to "force". So that and the fetch method solved the problem. Interesting that there is no mention about the fetch method in the docs for the youtube data api, only place i could find it was in the people api.

            – abobakrdy
            Mar 27 at 13:39











          • Google documentation isnt the same for all apis some are better documented then others. Drive is good for php so is google analytics my project has them generated for all the apis. Remember to accept the answer if it helped you.

            – DaImTo
            Mar 27 at 13:53







          • 1





            Accepted and upvoted your answer now. Yeah, ill that code sample looked good so ill probaly use it in the future for Google apis.

            – abobakrdy
            Mar 27 at 14:03










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55338017%2fyoutube-data-api-asks-for-consent-while-accesstype-is-set-to-offline%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You are applying your refresh token but not actually using it to fetch a new access token.



          $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
          $client->setAccessToken($client->getAccessToken());


          My sample Oauth2Authentication.php






          share|improve this answer























          • Thanks, i also didnt have any refresh token because i didnt set the approvalprompt parameter to "force". So that and the fetch method solved the problem. Interesting that there is no mention about the fetch method in the docs for the youtube data api, only place i could find it was in the people api.

            – abobakrdy
            Mar 27 at 13:39











          • Google documentation isnt the same for all apis some are better documented then others. Drive is good for php so is google analytics my project has them generated for all the apis. Remember to accept the answer if it helped you.

            – DaImTo
            Mar 27 at 13:53







          • 1





            Accepted and upvoted your answer now. Yeah, ill that code sample looked good so ill probaly use it in the future for Google apis.

            – abobakrdy
            Mar 27 at 14:03















          1














          You are applying your refresh token but not actually using it to fetch a new access token.



          $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
          $client->setAccessToken($client->getAccessToken());


          My sample Oauth2Authentication.php






          share|improve this answer























          • Thanks, i also didnt have any refresh token because i didnt set the approvalprompt parameter to "force". So that and the fetch method solved the problem. Interesting that there is no mention about the fetch method in the docs for the youtube data api, only place i could find it was in the people api.

            – abobakrdy
            Mar 27 at 13:39











          • Google documentation isnt the same for all apis some are better documented then others. Drive is good for php so is google analytics my project has them generated for all the apis. Remember to accept the answer if it helped you.

            – DaImTo
            Mar 27 at 13:53







          • 1





            Accepted and upvoted your answer now. Yeah, ill that code sample looked good so ill probaly use it in the future for Google apis.

            – abobakrdy
            Mar 27 at 14:03













          1












          1








          1







          You are applying your refresh token but not actually using it to fetch a new access token.



          $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
          $client->setAccessToken($client->getAccessToken());


          My sample Oauth2Authentication.php






          share|improve this answer













          You are applying your refresh token but not actually using it to fetch a new access token.



          $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
          $client->setAccessToken($client->getAccessToken());


          My sample Oauth2Authentication.php







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 26 at 9:47









          DaImToDaImTo

          49k11 gold badges78 silver badges262 bronze badges




          49k11 gold badges78 silver badges262 bronze badges












          • Thanks, i also didnt have any refresh token because i didnt set the approvalprompt parameter to "force". So that and the fetch method solved the problem. Interesting that there is no mention about the fetch method in the docs for the youtube data api, only place i could find it was in the people api.

            – abobakrdy
            Mar 27 at 13:39











          • Google documentation isnt the same for all apis some are better documented then others. Drive is good for php so is google analytics my project has them generated for all the apis. Remember to accept the answer if it helped you.

            – DaImTo
            Mar 27 at 13:53







          • 1





            Accepted and upvoted your answer now. Yeah, ill that code sample looked good so ill probaly use it in the future for Google apis.

            – abobakrdy
            Mar 27 at 14:03

















          • Thanks, i also didnt have any refresh token because i didnt set the approvalprompt parameter to "force". So that and the fetch method solved the problem. Interesting that there is no mention about the fetch method in the docs for the youtube data api, only place i could find it was in the people api.

            – abobakrdy
            Mar 27 at 13:39











          • Google documentation isnt the same for all apis some are better documented then others. Drive is good for php so is google analytics my project has them generated for all the apis. Remember to accept the answer if it helped you.

            – DaImTo
            Mar 27 at 13:53







          • 1





            Accepted and upvoted your answer now. Yeah, ill that code sample looked good so ill probaly use it in the future for Google apis.

            – abobakrdy
            Mar 27 at 14:03
















          Thanks, i also didnt have any refresh token because i didnt set the approvalprompt parameter to "force". So that and the fetch method solved the problem. Interesting that there is no mention about the fetch method in the docs for the youtube data api, only place i could find it was in the people api.

          – abobakrdy
          Mar 27 at 13:39





          Thanks, i also didnt have any refresh token because i didnt set the approvalprompt parameter to "force". So that and the fetch method solved the problem. Interesting that there is no mention about the fetch method in the docs for the youtube data api, only place i could find it was in the people api.

          – abobakrdy
          Mar 27 at 13:39













          Google documentation isnt the same for all apis some are better documented then others. Drive is good for php so is google analytics my project has them generated for all the apis. Remember to accept the answer if it helped you.

          – DaImTo
          Mar 27 at 13:53






          Google documentation isnt the same for all apis some are better documented then others. Drive is good for php so is google analytics my project has them generated for all the apis. Remember to accept the answer if it helped you.

          – DaImTo
          Mar 27 at 13:53





          1




          1





          Accepted and upvoted your answer now. Yeah, ill that code sample looked good so ill probaly use it in the future for Google apis.

          – abobakrdy
          Mar 27 at 14:03





          Accepted and upvoted your answer now. Yeah, ill that code sample looked good so ill probaly use it in the future for Google apis.

          – abobakrdy
          Mar 27 at 14:03








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55338017%2fyoutube-data-api-asks-for-consent-while-accesstype-is-set-to-offline%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현