php - Google OAuth 2.0 - User needs to re-consent on EVERY refresh? -
i've been creating little script grab youtube monthly views user's youtube channel. script works fine every time refresh page have reconsent access. i'd prefer go away can't find solution online.
i've had @ refresh tokens when add together them on refresh users still has re-request info again, maybe it's creating user session or storing cookie?
here's current working script
if(isset($_get['code'])) { // seek access token $code = $_get['code']; $url = 'https://accounts.google.com/o/oauth2/token'; // our post info send oauth server in exchange // access token $params = array( "code" => $code, "client_id" => $oauth2_client_id, "client_secret" => $oauth2_secret, "redirect_uri" => $oauth2_redirect, "grant_type" => "authorization_code" ); // build new http post request $request = new httppost($url); $request->setpostdata($params); $request->send(); // decode incoming string json $responseobj = json_decode($request->gethttpresponse()); $currentdate = date("y-m-d"); $monthbefore = date('y-m-d', strtotime(date('y-m')." -1 month")); $views = file_get_contents('https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel%3d%3dmine&start-date='.$monthbefore.'&end-date='.$currentdate.'&metrics=views&access_token='.$responseobj->access_token); $json = json_decode($views); } $monthlyviews = $json->rows[0][0]; var_dump($monthlyviews);
php json youtube-api google-oauth
No comments:
Post a Comment