Closed benlk closed 7 years ago
We can't be using header()
here because the headers have already been sent.
To do:
Dunno why we're changing the headers.
But moving the header modifications into a separate action (efe7fc6c6491000de02c578906e732284683ec71) fixes this enough that #61 begins to occur reliably.
After removing the code
parameter from the URL, a Google_Auth_Exception for invalid code:
Fatal error: Uncaught Google_Auth_Exception: Invalid code in /srv/www/testing/htdocs/wp-content/plugins/ga-popular-posts/api/src/Google/Auth/OAuth2.php:88
Stack trace:
- /srv/www/testing/htdocs/wp-content/plugins/ga-popular-posts/api/src/Google/Client.php(120): Google_Auth_OAuth2->authenticate(NULL)
- /srv/www/testing/htdocs/wp-content/plugins/ga-popular-posts/AnalyticBridgeGoogleClient.php(189): Google_Client->authenticate(NULL)
- /srv/www/testing/htdocs/wp-content/plugins/ga-popular-posts/inc/analytic-bridge-blog-options.php(133): analytic_bridge_authenticate_google_client(NULL)
- /srv/www/testing/htdocs/wp-includes/class-wp-hook.php(298): analyticbridge_option_page_html('')
- /srv/www/testing/htdocs/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters('', Array)
- /srv/www/testing/htdocs/wp-includes/plugin.php(453): WP_Hook->do_action(Array)
- /srv/www/testing/htdocs/wp-admin/admin.php(222): do_action('settings_page_a...')
- /srv/www/testing/htdocs/wp-admin/options-general.php(10): require_once('/srv/www/ in /srv/www/testing/htdocs/wp-content/plugins/ga-popular-posts/api/src/Google/Auth/OAuth2.php on line 88
/* Google has posted an authenticate code back to us. */
if ( isset($_GET['code']) ) {
$client = analytic_bridge_authenticate_google_client($_GET['code']);
// @see analyticbridge_google_authenticate_code_post();
// No auth ticket loaded (yet).
} elseif ( !get_option('analyticbridge_access_token') ) {
$client = analytic_bridge_authenticate_google_client($_GET['code']);
$client = analytic_bridge_google_client(false);
echo "<a href='" . $client->createAuthUrl() . "'>Connect</a>";
Why are we using $_GET to generate $client? It's not set.
Fixed that in https://github.com/INN/Google-Analytics-Popular-Posts/commit/dc45e72a4de318d9b992baaa42442128f91b145f
Now, with the URL having $code set in it: http://testing.dev/wp-admin/options-general.php?page=analytic-bridge&code=snipped
Fatal error: Uncaught TypeError: Argument 1 passed to Google_Service_Oauth2::__construct() must be an instance of Google_Client, boolean given, called in /srv/www/testing/htdocs/wp-content/plugins/ga-popular-posts/inc/analytic-bridge-blog-options.php on line 369 and defined in /srv/www/testing/htdocs/wp-content/plugins/ga-popular-posts/api/src/Google/Service/Oauth2.php:52
Stack trace:
- /srv/www/testing/htdocs/wp-content/plugins/ga-popular-posts/inc/analytic-bridge-blog-options.php(369): Google_Service_Oauth2->__construct(false)
- /srv/www/testing/htdocs/wp-admin/includes/template.php(1343): analyticbridge_setting_api_token_connect_button(Array)
- /srv/www/testing/htdocs/wp-admin/includes/template.php(1302): do_settings_fields('analytic-bridge', 'largo_anaytic_b...')
- /srv/www/testing/htdocs/wp-content/plugins/ga-popular-posts/inc/analytic-bridge-blog-options.php(120): do_settings_sections('analytic-bridge')
- /srv/www/testing/htdocs/wp-includes/class-wp-hook.php(298): analyticbridge_option_page_html('')
- /srv/www in /srv/www/testing/htdocs/wp-content/plugins/ga-popular-posts/api/src/Google/Service/Oauth2.php on line 52
This is in the https://github.com/INN/Google-Analytics-Popular-Posts/tree/59-error-in-signup-process branch.
When you mess up the installation, you have to delete the app's access to your account in https://security.google.com/settings/u/0/security/permissions before retrying, because for some reason it only sends the required refresh token on the first try.
Removing code
from the url solves this problem:
http://testing.dev/wp-admin/options-general.php?page=analytic-bridge&code=snipped
Fatal error: Uncaught TypeError: Argument 1 passed to Google_Service_Oauth2::__construct() must be an instance of Google_Client, boolean given, called in /srv/www/testing/htdocs/wp-content/plugins/ga-popular-posts/inc/analytic-bridge-blog-options.php on line 367 and defined in /srv/www/testing/htdocs/wp-content/plugins/ga-popular-posts/api/src/Google/Service/Oauth2.php:52 Stack trace: #0 /srv/www/testing/htdocs/wp-content/plugins/ga-popular-posts/inc/analytic-bridge-blog-options.php(367): Google_Service_Oauth2->__construct(false) #1 /srv/www/testing/htdocs/wp-admin/includes/template.php(1343): analyticbridge_setting_api_token_connect_button(Array) #2 /srv/www/testing/htdocs/wp-admin/includes/template.php(1302): do_settings_fields('analytic-bridge', 'largo_anaytic_b...') #3 /srv/www/testing/htdocs/wp-content/plugins/ga-popular-posts/inc/analytic-bridge-blog-options.php(120): do_settings_sections('analytic-bridge') #4 /srv/www/testing/htdocs/wp-includes/class-wp-hook.php(298): analyticbridge_option_page_html('') #5 /srv/www in /srv/www/testing/htdocs/wp-content/plugins/ga-popular-posts/api/src/Google/Service/Oauth2.php on line 52
So we need to figure out how to reliably remove the code
parameter from the URL after the site does what it needs to do with it.
So new workflow:
Seen at http://testing.dev/wp-admin/options-general.php?page=analytic-bridge