According to Google, OAuth 1.0 was official deprecated on April 20, 2012 (Google OAuth 1.0 Reference). They suggest migration to OAuth 2.0 as soon as possible.
The attached patch adds full OAuth 2.0 support while still ensuring full compatibility with all aspects of the Google Analytics Reports module.
UPDATE
The new implementation of OAuth2 kills the reports page thus. We rolled up all this functionality in one patch:
https://www.drupal.org/node/2488754
#1678306: Add Support for OAuth2 Authentication
#2368151: Build reports in Reports module on Views
#2169159: Migrate from Chart module to Charts
Comments
Comment #1
grendzy CreditAttribution: grendzy commentedThanks for the patch.
The downside of upgrading now is OAuth 2.0 is significantly more burdensome for the user, due to the need to "register" the app manually to obtain the client id / secret. (From what I can see, that's not an inherent weakness of 2.0, but a decision Google made to discontinue using the "anonymous" keys).
Since we potentially have until 2015, it's worth considering if the added ease of use justifies sticking with 1.0 for a while longer.
Alternatively, we might be able to create a throwaway google account, register the app once, and include the id / secret in the module's source code. From https://developers.google.com/accounts/docs/OAuth2InstalledApp :
Comment #2
jplaut CreditAttribution: jplaut commentedThat is a good point regarding the ease of use of OAuth 1.0 as compared to OAuth 2.0. This complication seems unavoidable, however.
I looked into your suggestion and I think that creating a throwaway registration with installed app settings won't work. Given the redirect URIs that are automatically created in that case, the client would either need to be running their app on a local server or within an environment that could track when a new page is opened.
Perhaps the module could give users the choice whether to use OAuth 1.0 or 2.0. It seems like the added security and continuing support of OAuth 2.0 might be better for some users.
Comment #3
yaho CreditAttribution: yaho commentedWSOD with this error after patching:
Fatal error: Call to a member function queryReportFeed() on a non-object in /home/www/********/www/sites/all/modules/google_analytics_reports/google_analytics_api.module on line 180
Thanks
Comment #4
jplaut CreditAttribution: jplaut commentedUPDATE
Patch has been updated to improve post-authentication redirection.
Comment #5
jplaut CreditAttribution: jplaut commentedUPDATE
Another update to prevent WSOD when calling report query functions.
Comment #6
grendzy CreditAttribution: grendzy commentedI had a chance to talk with Google's developer relations last week. They gave us the go-ahead to code this as an installed application.
Comment #7
grendzy CreditAttribution: grendzy commentedI've registered the app, and this is our API access info:
Client ID: 1077211914105.apps.googleusercontent.com
Client secret: aSqdPmaoktHWfENAwwfs2ma_
Redirect URIs: urn:ietf:wg:oauth:2.0:oob
The quota is currently 50,000 requests per day, but Google is willing to raise the limit once the app is reviewed.
Comment #8
yaho CreditAttribution: yaho commentedAfter patching from #5 works like a charm!
So thanks a lot! :-)
Comment #9
navarrete CreditAttribution: navarrete commentedI had many problems with connecting to Analytics these days. With the path changes of 6.x-1.3 version ( http://drupalcode.org/project/google_analytics_reports.git/commitdiff/ab... ) was not enought
But this parch with the paths modified works fine to me. And I think with a better conexion than 6.x-1.3 module version.
You must first enter the Google Analytics API console and create a kind of OAuth 2.0 authorization
-------------------------------------------------- ---------------------------
Client ID for web applications
Client ID: xxxxxxxxxxxxxxxxxxxx
Email address: xxxxxxxxxxxxxxxxxxxxx
Client secret: xxxxxxxxxxxxxxxxxxxxxx
Redirect URIs: http://your-domain/admin/settings/google-analytics-reports
JavaScript Origins: http://your-domain
-------------------------------------------------- -----------------------
Then we establish the connection with our client clientID and secret inside drupal module. With this kind of connection I get a Traffic reporting and quota information trough google api console . And you can set a higher limit requests per second and user than allowing other connection.
I leave the last version of the patch in two versions, both to modify on 6.x-1.2 and for 6.x-1.3
Comment #10
Andreas Radloff CreditAttribution: Andreas Radloff commentedHere is a patch for 7.x-3.x, it might be a bit rough since I've never looked through this module or this API before, it works for me though.
Comment #11
Andreas Radloff CreditAttribution: Andreas Radloff commented@grendzy, is the quota per user of the app or for the app total? If it's the later I strongly think another approach is better, I'm using up my quota fast and that's just one (admittedly huge) site.
I also wonder if this will mean that an individual user does not have access to the api statistics / dashboard? This is a feature at least I appreciate. Maybe we could provide a setting for using either your preconfigured IDs or providing a own set of keys?
Comment #12
grendzy CreditAttribution: grendzy commentedThanks for picking up the patch. I do want to continue with the "installed app" approach as requested by the Google developer relations team. There will be a global quota, and a per-site quota. I have been told not to worry too much about the quota and that it can be raised in proportion to the size of our userbase.
Ease of installation for newbies is a priority for raspberryman and myself so we want the keys in #7 to be the default.
I agree that allowing advanced users to provide their own client ID makes sense. Ideally I'd like to see this under an "advanced" fieldset that's collapsed by default so new users understand the whole app registration process is not required.
Comment #13
drplHello,
I applied the "google_analytics_reports-oauth2_support_update_6.x-1.3_18.09.2012.patch" it's working fine with me.
but when It gives me limit exceeded at 10k.
Comment #14
kalpeshhpatel CreditAttribution: kalpeshhpatel commentedHello I am facing the same issue. For version 7.x-1.3.
When I see report it shows the error of Method not allowed with error 405.
Can anyone suggest, how can I resolve it. I have tried the patch but it's not working.
-- Thanks
Comment #14.0
kalpeshhpatel CreditAttribution: kalpeshhpatel commentedUpdated patch.
Comment #15
Plazik CreditAttribution: Plazik commentedGoogle Auth module https://www.drupal.org/project/gauth provides Google OAuth2 authentication. I think we should use this module.
Comment #16
Plazik CreditAttribution: Plazik commentedhttps://support.google.com/accounts/answer/6140397
Comment #17
Luke_Nuke CreditAttribution: Luke_Nuke commentedSo... after 3 days OAuth 1.0 will be shut off and this module will stop working? And I believe it's the main integration with GA API solution for Drupal right now, that is used by 12 784 websites. Bad times :( .
Comment #18
Luke_Nuke CreditAttribution: Luke_Nuke commentedComment #19
dobe CreditAttribution: dobe commentedThis is a reroll of #10 to current dev. I was able to revoke the access key re apply it and connect to grab the profiles on the config form. So I am assuming most should work. I have not checked views integration or anything.
Comment #20
dobe CreditAttribution: dobe as a volunteer commentedSome updates. I have tested the views implementation and this patch resolves some issues uncovered from my previous.
Comment #21
Martijn Houtman CreditAttribution: Martijn Houtman commentedApplied patch #20, works fine for me. Please do not that if you use the reporting API in your custom module (as I do): the response structure has changed a bit, so check your code.
Comment #22
togbonna CreditAttribution: togbonna commentedPatch #20 apparently works. But I get the following warning when I try to view the Google Analytics Summary page under Reports:
The configurations authenticates successfully, but for some reasons the summary report doesn't show.
What am I missing?
Comment #23
dobe CreditAttribution: dobe as a volunteer commentedIll look into this. I had not used the summary page.
Comment #24
dobe CreditAttribution: dobe as a volunteer commentedI am guessing your having issues based on this: https://www.drupal.org/node/2169159. Can you give any details to if you applied this other patch? Etc.
Comment #25
dobe CreditAttribution: dobe as a volunteer commentedI have combined all the patches so it is just one. It will hopefully make it easier for applying so we can get this to dev.
Comment #26
scotthooker CreditAttribution: scotthooker commentedWhen updating using this patch. What should the redirect URI link be?
Comment #27
dobe CreditAttribution: dobe as a volunteer commentedI believe it is "http://yourdomain.com/admin/config/system/google-analytics-reports-api"
Comment #28
togbonna CreditAttribution: togbonna as a volunteer commentedGreat! The combined patch on https://www.drupal.org/node/2488754 resolved the issue. Thanks.
Minor issues though: The summary page link no longer appears under the Reports menu. Had to go directly to the URL, 'admin/reports/google-analytics/detail' to access the page.
And I believe the page title should read 'Google Analytics Summary', instead of 'Content Detail', like before.
Comment #29
dobe CreditAttribution: dobe as a volunteer commentedClearing cache didn't fix it?
Comment #30
togbonna CreditAttribution: togbonna as a volunteer commentedNo, it did not, but I noticed that the menu item
'$items['admin/reports/google-analytics']' = array( ... );
is missing from google_analytics_reports_menu().Comment #31
emerham CreditAttribution: emerham as a volunteer commentedSettings wont save when selecting the site data to use. I have multiple sites on one Google account and it is only pulling session data from the first list in the list.
Comment #32
neale.wolfson CreditAttribution: neale.wolfson commentedTrying to get this up and running but well 'issues' :)
Big issue so far I've struct is the development of the return url. currentUrl()
We're running on Acquia infrastructure, so we have our ssl to the proxy server, and then standard to the server itself.
Secure is turned on, but the structure of the call is such that it totally messes up the return URL. (In short the return URL is https://abc.com.au:80/)
I'm not fully certain the best way to fix this one (To continue testing I've hard coded the address :) So I
m leaving it up to the folks here.
Smaller issue.
I think this might be an issue with the base Version but...
We're using multi domain code, and domain_conf. Because it's not loaded all the time the admin_form function is missing. (A include_once should do it)
And a comment.
Perhaps we could do with more checks on the responses we get from Google. I found I'd forgotten to turn on the API and that the error message generated by the system had 'disappeared' by the time it was returned to my code.
Apologies to giving more problems not solutions, I'm working to deadline and trying to either get it working fully, or putting it off til later.
Comment #33
bigmonmulgrew CreditAttribution: bigmonmulgrew commentedI'm unable to set a profile Attempting to set a profile also generates 2 errors.
Notice: Undefined index: google_analytics_reports_profile_id in google_analytics_reports_api_admin_submit() (line 183 of /var/www/sites/all/modules/google_analytics_reports/google_analytics_reports_api/google_analytics_reports_api.pages.inc).
Notice: Undefined index: google_analytics_reports_cache_length in google_analytics_reports_api_admin_submit() (line 184 of /var/www/sites/all/modules/google_analytics_reports/google_analytics_reports_api/google_analytics_reports_api.pages.inc).
It refers to this code
Sadly I don't know enough about this to help fix it but I thought I'd at least give some additional info.
Comment #34
Helgi Andri Jónsson CreditAttribution: Helgi Andri Jónsson commentedIn the google_analytics_report_api.lib.inc query parameters must be passed to drupal_goto in the second argument of the function as below:
Comment #35
dobe CreditAttribution: dobe as a volunteer commentedThis function seems to need to make use of drupal_parse_url() as well. I will see about messing with this a bit.
Comment #36
aparnakondala1 CreditAttribution: aparnakondala1 commentedFor setting profile, Please correct lines in
google_analytics_reports_api.pages.inc
variable_set('google_analytics_reports_cache_length', $form_state['values']['google_analytics_reports_api_cache_length']);
variable_set('google_analytics_reports_profile_id', $form_state['values']['google_analytics_reports_api_profile_id']);
variable_set('google_analytics_reports_cache_length', $form_state['values']['google_analytics_reports_api_cache_length']);
Comment #37
craigshaddick CreditAttribution: craigshaddick commentedI ran into the same problem as aparnakondala123, have created a patch for it.
Comment #38
dnd CreditAttribution: dnd commentedHi, I've problem with connecting my site to google, when I try to run reports i get message like "You should authenticate this site to use your Google Analytics account before you can view reports".
I've done:
On site:
1. Get newest google analitics (http://ftp.drupal.org/files/projects/google_analytics_reports-7.x-3.0-be...)
2. Run patch google_analytics_reports-oauth2-support_7.x-3.x_1678306-20.patch
3. Run patch google_analytics_reports-oauth2-support_7.x-3.x_1678306-37.patch
4. add modifications from (https://www.drupal.org/node/2488754#comment-9936008)
On google:
1. Create web app
2. Get ids from app and use it to configure google analitics reports (drupal)
3. Validate site and connect it with google analitisc, confirming everything
On drupal I can see my reports but when I try to run reports it fails.
Please help! I've spend a lot of time with than I ve no idea what could be wrong.
Comment #39
dobe CreditAttribution: dobe as a volunteer commented@dnd check my comment #24, The parent issue https://www.drupal.org/node/2488754 contains the auth patch + the reports page patch.
Comment #40
emerham CreditAttribution: emerham as a volunteer commenteddnd, if you are trying from the admin menu you need to add /detail to the end to get some of the data. There is a block you can add to a region and it will get the ga data for that page and there you can click a more link to get more information about that current page.
Comment #41
dnd CreditAttribution: dnd commented@emerham
works .... thank you! it seems I've done everything ok and there is a problem google anlitics reports
@dobe
I'm trying to solve it ... I've try to pach google_analytics_reports with https://www.drupal.org/files/issues/oauth_charts-1678306-2169159.patch but I've some problems, so I'm going to do it manualy (but maybe tomorrow :) today so tired (It's 00:00 in my time zone, and at 7:00 have to be at work ;)) Thanks! I'll report my work tomorrow.
Comment #42
lukee1234 CreditAttribution: lukee1234 commentedhow far away is a dev version with these updates?
Comment #43
Plazik CreditAttribution: Plazik commented@Luke_Nuke after "Review & tested by community".
Comment #44
alemadleiI had several problems applying the patch (whistespace errors) but in the end got it to work with SourceTree.
I had a problem though.
sites/all/modules/google_analytics_reports/google_analytics_reports_api/google_analytics_reports_api.lib.inc, protected function sanitizeReport.
$fields = google_analytics_reports_views_get_fields();
I removed that line. I don't need the reports module but this function was calling a function from that module.
The variable is used, but I don't seem to get anything wrong if I set it to an empty array.
Maybe the definition of those fields should be moved somewhere else, or the report module should be added as a dependency in the info file.
This is the process I followed:
Everything seems to to work as before.
Comment #45
dnd CreditAttribution: dnd commented@dobe
After patching still doesn't work, but this time when run from admin/reports/google-analytics I ve blank page.
Maybe I ve made a mistake in patching.
Can someone send me patched version (working) ? (my email: dnd@poczta.fm)
Thanks in advise!
Comment #46
alemadlei@dnd, using latest dev, I applied #1 from https://www.drupal.org/node/2488754 did the changes and that worked for me.
Comment #47
togbonna CreditAttribution: togbonna as a volunteer commented'Pageviews Over the Past 30 Days' chart values does not correspond with the one on Google Analytic dashboard page.
Comment #48
aotu CreditAttribution: aotu commentedPatch #1 applied and authenticated successfully, however now there's no reports page at: /admin/reports/google-analytics
Does anyone have a fix?
Comment #49
togbonna CreditAttribution: togbonna as a volunteer commented@aotu, go to /admin/reports/google-analytics/detail. No menu link though
Comment #50
dreamet CreditAttribution: dreamet commentedI have applied patch #10 but I am getting error.
Notice: Undefined index: HTTPS in GAFeed::currentUrl() (line 72 of /home/.................modules/google_analytics_reports/GAFeed.lib.inc).
and the watch dog displays
Code: 401 - Error: Unauthorized - Message: { "error" : "unauthorized_client" }
How can I get the full workable full package of this module?
Comment #51
dobe CreditAttribution: dobe as a volunteer commentedYou will have a better shot going to: https://www.drupal.org/node/2488754
Comment #52
dreamet CreditAttribution: dreamet commenteddnd, can you describe for me how? Patch google_analytics_reports-7.x-3.0-beta1 by using
1. Run patch google_analytics_reports-oauth2-support_7.x-3.x_1678306-20.patch
2. Run patch google_analytics_reports-oauth2-support_7.x-3.x_1678306-37.patch
There is no GAFeed.lib file in google_analytics_reports-7.x-3.0-beta1. can you help please or can you send?
dreamet2013@gmail.com
Comment #53
igasi CreditAttribution: igasi commentedSuscribe
Comment #54
dreamet CreditAttribution: dreamet commented@Andreas Radloff, I have applied #10 for version 7.x-3.0-beta1 but still I am getting error. Can someone send me patched version (working) ? (dreamet2013@gmail.com)
Notice: Undefined index: HTTPS in GAFeed::currentUrl() (line 72 of /home/.................modules/google_analytics_reports/GAFeed.lib.inc).
and the watch dog displays
Code: 401 - Error: Unauthorized - Message: { "error" : "unauthorized_client" }
Comment #55
dreamet CreditAttribution: dreamet commentedThanks.
Comment #56
GreenReaperAny love for 6.x-1.3, or a chance for a 6.x-1.4/2.0?
I tried applying the patch in #9 and it went on cleanly and even let me get an authentication page at Google once I'd figured out that I had to turn on the Analytics API.
However, when I returned to the site, although it *said* "You have been successfully authenticated.", I got this in the error log:
Code: 400 - Error: Bad Request - Message: { "error" : "redirect_uri_mismatch" }
Comment #57
dreamet CreditAttribution: dreamet commentedI am trying to OAuth2 Authentication and I am getting redirect_uri_mismatch error. My correct url is https://www.example.com/admin/config/system/google-analytics-reports-api but I am not sure why redirecting to https://www.example.com:80/admin/config/system/google-analytics-reports-api. Please help.
Error: redirect_uri_mismatch
The redirect URI in the request: https://www.example.com:80/admin/config/system/google-analytics-reports-api did not match a registered redirect URI.
Comment #58
dobe CreditAttribution: dobe as a volunteer commentedIs https setup on your website? If not you might want to try http. Port :80 is usually not a ssl port.
Comment #59
dreamet CreditAttribution: dreamet commentedYes https setup.
Comment #60
dobe CreditAttribution: dobe as a volunteer commented@dreamet have you downloaded latest dev and applied patch(s) at https://www.drupal.org/node/2488754?
Comment #61
dreamet CreditAttribution: dreamet commented@dobe, yes I applied patch and fine in my local but when I go live the redirection still appending :80.
https://www.example.com:80/admin/config/system/google-analytics-reports-api
What should I do if the https setup on server side? do you have any quick solution? Please I am running out of time.
Thank you in advance!
Comment #62
TomDude48 CreditAttribution: TomDude48 at LevelTen Interactive commentedI actually had the same problem with the redirect hosts on some of our servers. I added a config setting to override redirect host. Here is a patch to enable the override.
Comment #63
Pls CreditAttribution: Pls commentedFor anyone digging here and combining patches, here's one combined patch I uploaded to test it out faster - https://www.drupal.org/node/2488754#comment-9983195. Cheers for great work implementing OAuth2 guys!
Comment #64
cjamesrun CreditAttribution: cjamesrun commentedAny chance at all that this can be ported back to the 6.x release for OAuth 2.0?
Comment #65
dreamet CreditAttribution: dreamet commented@TomDude48. Thanks a lot. That is cool!
Comment #66
RumyanaRuseva CreditAttribution: RumyanaRuseva commentedThe patch from #9 worked perfectly for the 6.x-1.3 version.
The only tricky part is not to forget to set the correct Redirect URI when setting up the new client id.
Comment #67
attheshow CreditAttribution: attheshow commentedI was able to bypass the port 80 issue with the following edit to google_analytics_reports_api.pages.inc
$redirect_uri = GoogleAnalyticsReportsApiFeed::currentUrl();
Becomes:
Comment #68
MrDaleSmith CreditAttribution: MrDaleSmith at CTI Digital commentedJust to comment that Google have now removed Oauth 1 support entirely: I've installed the dev release of this module but authorisation takes you through to a Google issue saying Oauth 1 is no longer supported.
Comment #69
powysm CreditAttribution: powysm commentedI stumbled about with this a bit so these are the steps i needed to update hope it helps someone else. (Have not checked out zip)
Thanks to all other who contributed, which helped me.
Comment #70
Anonymous (not verified) CreditAttribution: Anonymous commentedIt seems like one of my sites which uses this module has also been bitten recently by Google shutting off support of OAuth v1. What is the best approach to getting this module working with OAuth v2?
Comment #71
Plazik CreditAttribution: Plazik as a volunteer commentedFixed in #2488754: OAuth & Charts, Integration.