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;
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
add a comment |
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
add a comment |
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
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
php google-api google-oauth youtube-data-api google-api-php-client
edited Mar 26 at 16:57
abobakrdy
asked Mar 25 at 12:39
abobakrdyabobakrdy
457 bronze badges
457 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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